mercredi 20 avril 2016

C# ObjectResult - adding more "columns" at runtime

Below is a simplified version of a web service method that pulls a tabular data from SQL stored procedure to pass to the front end. The "allLocations" object returned by the method is of type ObjectResult. What would be the best way of adding more "columns" at runtime? The values of the new columns would be inserted based on some if/else condition. Any help is appreciated.

    // GET: api/Locations/GetLocations
    [HttpGet]
    public IEnumerable<sp_GetLocations_Result> GetLocations()
    {

        // Initial object allLocations of ObjectResult type
        var allLocations = geoDB.sp_GetLocations(); 

        foreach (var loc in allLocations) 
        {
           // at runtime add more columns to tabular 
           // data and populate them based on some conditions
        }

        return allLocations; // allLocations object with more column now
    }




Aucun commentaire:

Enregistrer un commentaire