带有具体类继承的 EF
我有一组具有一定继承级别的实体。
abstract class A
{
...
}
class B: A //Non abstract B
{...}
class C : B //Non abstract C
由于 B 和 C 是具体类 i 我尝试设置 TPC 继承策略来获取数据库中 B 和 C 具体类的表。但是,因为我在 B 上执行了 MapInheritedProperties() ,并且 CI 从表 A 中获取了在表 C 中重复的列。我该如何阻止这种情况?我使用正确的继承策略吗?另外,当我保存对 C(仅)实体框架的更改时,会在表 B 中为 C 中的行创建一行。有没有办法防止这种情况?我不认为我的继承有什么问题。 我尝试的另一种方法是摆脱继承,对 B 和 C 使用 TPT,并使用导航属性链接 B 和 C。这种方法有效,但我不相信为什么第一种方法不起作用。
I have set of entities with some level of inheritance.
abstract class A
{
...
}
class B: A //Non abstract B
{...}
class C : B //Non abstract C
Since B and C are concrete classes i
I tried setting up TPC inheritance strategy to get tables for B and C concrete classes in the database. However, because i did MapInheritedProperties() on B and C I get columns from table A duplicated in table C. How do i stop this? Am i using right inheritance strategy? Also, when i save changes to C(only) entity framework creates a row in table B for a row in C. Is there a way to prevent this? I don't see anything wrong with my inheritance.
Another approach which i tried is getting rid of the inheritance and use TPT for B and C and used Navigation property to link B and C. This approach worked but i am not convinced on why first approach didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论