Using EF with dynamically generated tables

I’m currently using EF code-first as part of an ASP.Net Core application I’m building.

In my application, the user can design a table via a web interface (table name, column names, column types) that becomes a table in the database once saved.

My question is: Is there an easy way to perform the operations of creating, altering, and querying the data within these user-defined tables in EF? Since the tables are generated based on user input, they’re not part of the EF DbContext, and the number of columns and data types is unknown to EF.

I’ve started down the path of generating SQL strings and calling ExecuteSqlCommand, but I’m wondering if there’s a better way to approach this problem? Given that most of my data will ultimately live inside of these custom tables, I’m also considering switching away from EF and using Dapper with dynamic objects.

Any input is appreciated!

submitted by /u/IgnoreTheFrontPage
[link] [comments]

Leave a Reply