samedi 26 août 2017

Generate a class based on table schema

I want to dynamically generate a class based on the results from a query that user submits. For instance, if the user enters Select name, age from tbl, the result is a name column which is string and age which is an int. The resulting class should be:

public class Test
{
   public string Name { get; set; }
   public int Age { get; set; }
}

Is there an efficient way to do this via EntityFramework or features in C# or I have to use maybe reflection to create a new type and instantiate it.

PS: My purpose is to run this query on the database and show the results in a Grid to the user and run some filter/sort/etc. on it.





Aucun commentaire:

Enregistrer un commentaire