简体   繁体   English

实体框架配置问题(EF Code-First)

[英]Entity Framework Configuration Question (EF Code-First)

I'm using table per hiearchy for the following model:我为以下 model 使用每个层次结构的表:

Story (base class) - Individual Story (sub class) - Team Story (sub class)故事(基类)-个人故事(子类)-团队故事(子类)

I column in my table that I want to share between both derived types, but I would like to name it differently in each class.我在我的表中列出了我想在两种派生类型之间共享的列,但我想在每个 class 中以不同的方式命名它。 Is this possible?这可能吗? I tried a few different things but could not get it to work out correctly (can dig up the exact exception tomrrow at work if need be).我尝试了一些不同的方法,但无法正确解决(如果需要,可以在工作中挖掘确切的异常)。

Thanks!谢谢!

No it is not possible.不,这是不可能的。 The column is mapped to property in the base class and this property is derived in sub classes.该列映射到基础 class 中的属性,并且该属性派生在子类中。 You cannot change the name of property in derived class and EF doesn't allow mapping shared properties in derived classes (they must be mapped in the base class).您不能更改派生 class 中的属性名称,并且 EF 不允许在派生类中映射共享属性(它们必须在基类中映射)。

If by "share", you mean that you'd like both subclasses to use that database field (but NOT the base class) just with different names, that should work as long as it's not the discriminator column.如果通过“共享”,您的意思是您希望两个子类都使用具有不同名称的数据库字段(但不是基类),只要它不是鉴别器列,这应该可以工作。 Just create scalar properties on each subtype and map the appropriate property to the common field.只需在每个子类型上创建标量属性,然后 map 为公共字段创建适当的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM