忽略列,但首先通过存储过程EF代码填充属性

时间:2015-01-27 13:45:38

标签: ef-code-first entity-framework-6

我通过流畅的API忽略了一个列,但是想在使用某些逻辑执行存储过程时填充该属性。但它没有映射被忽略的列属性。如果有任何方法可以首先在Entity框架代码中告诉我。

1 个答案:

答案 0 :(得分:1)

我最近遇到了同样的问题。我找到的唯一解决方案是类层次结构:

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

P.S。不要将类MyEntityBase标记为ABSTRACT - EF会将此关系映射为数据库继承。