如何使用 Entity Framework 4.0 将相同的实体映射到相同的表?
在我的概念模型中,我有一个“盒子”,可以包含“x”个小部件。有些小部件可以存档并且不经常访问。一个盒子可以包含一个或多个小部件。为了支持最大的数据库性能,我想使用两个相同的数据库表;一种用于普通小部件,另一种用于存档小部件。我不希望 Box 实体有两个不同的小部件集合,例如 IList
,只是一个包含已存档和活动小部件的列表。
如何将“Box”实体映射到同时使用存档表和活动表的“Widget”实体?
In my conceptual model I have a 'Box' that can contain 'x' number of widgets. Some of the widgets can be archived and are accessed infrequently. A box can contain one or more widgets. To support maximum database performance I want to use two identical database tables; one for normal widgets and one for archived widgets. I don't want the Box entity to have two different collections of widgets, eg IList<ArchiveWidget> & IList<Widget>
, just one that contains both archived and active widgets.
How can I map the 'Box' entity to the 'Widget' entity that uses the archive and active tables at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试解决此问题:创建一个 NewWidget 和 ArchivedWidget 联合的视图。这适用于读取数据。
另一种选择是进入 edmx 文件并尝试在那里修复它。但我认为这是不可能的,因为如果您创建一个新的小部件并说保存,EF 将不知道将其放入哪个表中。
您可以使用这两种类型生成 EF 模型,然后将类型定义移动到两个小部件都继承自的基类。我没有尝试过这个,因此不确定它是否有效。
There is on way you could try to solve this: Create a view that is a union of NewWidget and ArchivedWidget. This would work for reading data.
Another alternative is to go into the edmx file and try an fix it there. But I do not think that this is possible, since if you create a new widget and say save, EF would not know which table to put it in.
You could generate the EF model with the two types, then move the type definition into a base class, which both of the widget inherit from. I have not tried this, therefore not sure if it will work.