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

Ignore column but populate property through stored procedure EF code first

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

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

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。不要将 class MyEntityBase 标记为 ABSTRACT - EF 会将此关系映射为数据库继承。