【发布时间】:2015-01-27 13:45:38
【问题描述】:
我通过 fluent API 忽略了一个列,但想在使用某些逻辑执行存储过程时填充该属性。但它没有映射忽略的列属性。请让我知道是否有任何方法可以先在实体框架代码中执行此操作。
【问题讨论】:
标签: ef-code-first entity-framework-6
我通过 fluent API 忽略了一个列,但想在使用某些逻辑执行存储过程时填充该属性。但它没有映射忽略的列属性。请让我知道是否有任何方法可以先在实体框架代码中执行此操作。
【问题讨论】:
标签: ef-code-first entity-framework-6
我最近遇到了同样的问题。我找到的唯一解决方案是类层次结构:
public class MyEntityBase {
public int Id { get; set; }
}
public class MyEntity: MyEntityBase {
...
}//This class is mapped to DB with a fluent API and does not contain ignored property.
//Also it does not have derivative classes, so EF will not create class inheritance in DB.
public class DerivedEntity: MyEntityBase {
public int IgnoredProperty { get; set; }
}//Use this class while executing stored procedures
附:不要将 MyEntityBase 类标记为 ABSTRACT - EF 会将这种关系映射为数据库继承。
【讨论】: