Entity Framework 4.1 动态生成表

发布于 2024-12-02 21:48:47 字数 297 浏览 1 评论 0原文

我有两个模型;用户和客户。一个用户可以有多个客户端,一个客户端可以有一个用户。项目经理坚持每个用户客户端都位于单独的中,因此我必须为创建的每个用户动态生成新表。例如,用户 ABC 将有一个名为 ABC_Clients 的新表,用户 XXX 将有一个名为 XXX_Clients 的单独表,依此类推。我的问题:如何使用实体框架做到这一点?我可以简单地执行一个过程来创建新表并使用 ExecuteStoreQuery() 进行手动查询,但它似乎并没有拉回关系(即延迟加载),我是否必须构建查询以某种方式或其他方式?

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 or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-12-09 21:48:47

这就是优秀的设计。它将非常易于使用并且非常易于维护。祝贺你的经理,告诉他做好他的工作,让你做你的。项目经理不是建筑师,而且通常是技术知识较差的人。

EF 无法支持这一点。您必须完全使用 SQL(在本例中实际上是动态 SQL)和旧的 ADO.NET 来完成此操作。 ExecuteStoreQuery 永远不会返回关系 - 它无法做到这一点。延迟加载不能很好地工作,因为标准延迟加载是基于与实体框架映射的静态数据库结构。您的 Client 实体无法由 EF 映射,因为它要求每个实体仅映射一次(= 在继承或拆分的情况下映射到一个表或一组相关表)。您的 Client 实体需要映射的次数与 User 表中用户的数量一样多。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文