开发者

Entity Framework 4.1 Dynamically Generated Tables

开发者 https://www.devze.com 2023-04-02 12:05 出处:网络
I have two models; User and Client. A user can have many clients and a client has one user. The project manager insists each users clients to be in a separate table so I must dynamically generate new

I have two models; User and Client. A user can have many clients and a client has one user. The project manager insists each users clients to be in a separate table so I must dynamically generate new tables for each user that is created. For example user ABC will have a new table called ABC_Clients, user XXX will have a separate table called XXX_Clients and so forth. My question: how do I do this with Entity Framework? I can simply execute a procedure to create the new table and do an manual query with ExecuteStoreQuery() but it doesn't seem to pull relationships back (i.e. Lazy Load), do I have to construct my query in a certain way o开发者_C百科r something?


That is excellent design. It will be really easy to use and really nice to maintain. Congratulate your manager and tell him to do his job and let you do yours. Project manager is not architect and most often it is person with poor technical knowledge.

There is no way to support this with EF. You must do it completely with SQL (actually dynamic SQL in this case) and old ADO.NET. ExecuteStoreQuery never returns relations - it is not able to do that. Lazy loading cannot work as well because standard lazy loading is based on static database structure mapped with Entity framework. Your Client entity cannot be mapped by EF because it demands that each entity will be mapped only once (= to one table or set of related tables in case of inheritance or splitting). Your Client entity would need to be mapped as many times as you have users in your User table.

0

精彩评论

暂无评论...
验证码 换一张
取 消