实体框架表每个层次结构的限制

发布于 2025-01-02 01:22:20 字数 224 浏览 1 评论 0原文

我的数据库中有一个非常大的表,无法修改它。 所以我有表的 BaseEntity 类型。

我有几个孩子(entity1、entity2),我想将每种类型映射到同一列(“日期”)并以不同的方式命名属性。

当然,我无法将所有相同的列属性移动到基本类型,因为我的超级表中有大约 100 列(这不是我的设计,我只是需要映射它)

所以我有 0019 错误,有什么方法可以解决它或者 EF 不适合我?

I have very big table in my Database and a can't modify it.
So i have BaseEntity type for table.

I have several children (entity1, entity2) and i'd like to map each type to same column ("Date") and name properties differently.

Surely i can't move all same column properties to base type cause there is about 100 columns in my super table (it's not my design i've jst need to map it)

So i have 0019 error and is there any way to solve it or EF not for me?

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

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

发布评论

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

评论(1

你是我的挚爱i 2025-01-09 01:22:20

不可以。TPH 要求派生实体中定义的每个属性对于该实体来说是独占的(没有其他实体可以映射到同一列)。这针对 EF 中更通用的规则 - 每列只能映射一次。因此,如果您需要在更多实体中使用某些列,则必须在父实体中定义该列,并且在所有子实体中必须具有相同的名称。

No. TPH requires that each property defined in derived entity is exclusive for that entity (no other entity can map to the same column). This targets more general rule in EF - each column can be mapped only once. So if you need to use some column in more entities it must be defined in parent and must have same name in all child entities.

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