在 EF4 中动态创建表并使用它
假设我想动态创建一个名为 Customer-orders 的表,就像我希望每个客户在运行时都有自己的表一样,然后在 EF4 中正常使用它。
我正在使用 POCO 的代码优先方法。
这在 EF4 中可能吗,知道如何实现吗?
预先感谢任何指导我完成此任务的提示或信息......
Lets say i want to create a table called Customer-orders dynamically like if i want each customer to has its own Table at run-time and then work with it normally in EF4.
i`m using Code-first Approach with POCO.
is that possible in EF4 , any idea how to accomplish that ?
thanks in advance for any tips or info that direct me to accomplish this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表的名称是通过映射定义的。基本上,如果您有一些代码可以为映射提供正确的表名称,那么理论上应该是可能的。实际上这是错误的做法。模型必须在上下文使用之前进行编译。在正常情况下,模型仅在第一次使用上下文时编译一次,然后在内部缓存和重用,因为编译模型是 EF 中性能成本最高的操作(对于大型模型,可能需要数十秒),我认为它也是内存中相当大的数据结构。如果您想更改每个客户的单个表的映射,您需要每个客户的特殊编译模型,并且您必须仅将其用于该客户。将会很难处理。
Name of table is defined by mapping. Basically if you have some code which will provide correct table name to the mapping it should be theoretically possible. Practically it is wrong approach. Model must be compiled before it is used by context. In normal scenario the model is compiled only once when the context is first used and then it is internally cached and reused because compiling model is the most performance costly operation in EF (for large models it can take tens seconds) and I think it is also quite large data structure in memory. If you want to change mapping of single table per customer you need special compiled model per each customer and you must use it only for that customer. It will be difficult to handle.