Unknown return types from SQL queries?

I have a WPF application that has methods that pull T SQL queries from a database table:

enter image description here

  public List<AwardsChartParameters> GetAwardsChartParameters(string country, string articleType)
    {                    
         var query = (from a in _Context.tbQueryTable
                      where a.ArticleType == ArticleType
                      select a.ColSelection + " " + a.FromTable + " " + a.whereclause + " " + a.orderBY);

         string queryResult = query.FirstOrDefault().ToString();

         return ((IObjectContextAdapter)_Context).ObjectContext.ExecuteStoreQuery<AwardsChartParameters>(queryResult).ToList();
    }

      

Thus, depending on the ArticleType passed as a parameter from the UI, it returns one of several result sets from the pivot query defined in the table.

I am currently trying to write a class for every possible result set, eg.

public class AwardsChartParameters
{
    public string operator_int_name { get; set; }
    public int countAll { get; set; }
}

      

This particular query on the table will return a list of strings and int, so I can cast the results into mine List<AwardsChartParameters>

and draw them in my UI. Thus, I will need a class to store all possible result sets from the table as the table grows.

Is there a way to create a dynamic list or class that is generated at runtime depending on the result set from the query. For example, custom 1st query can return a list of strings, second query returns a list of strings and ints?

I am using Entity Framework, so I bind objects to specific classes in sql Server db in other parts of the code, but with result sets from queries in a table like this, I have specific dependencies to the result structure and I start to smell bad code ...

+3


source to share





All Articles