I don’t know much about the mechanics of how ORM tools work, but from working with Entity Framework (EF), I know it’s somehow possible to auto-generate CLR classes from arbitrary Views stored in a database. In EF these classes are auto-generated from your entity model. EF can even get column information from a stored procedure and generate a new “complex type” from this information.
- How is it possible auto-generate .NET classes, using only (1) the information provided by the SQL SELECT statement and (2) the ability to query the database for its metadata?
Because the SQL is stored in a database, we know at compile time what the SELECT SQL is. Similarly, Entity Framework knows what a View or stored procedure’s SELECT SQL is at compile time. We want to auto-generate .NET classes from knowing the SELECT SQL and querying the database’s metadata. I need to be able to transform the resulting single DataTable into the auto-generated classes.
It seems like the answer to my question lies in having knowledge of ORM tools;
- is there an ORM tool out there that can already do what I need, or
- could you explain how Entity Framework auto-generates its .NET classes from Views and Stored Procedures?
- Or if you can come up with another solution to auto-generating classes for my scenario, that would also be appreciated.
If any clarification is needed, just let me know.
I figured out how to do this. I wrote a very basic solution to this here.