【问题标题】:Ignore column but populate property through stored procedure EF code first忽略列但首先通过存储过程 EF 代码填充属性
【发布时间】:2015-01-27 13:45:38
【问题描述】:

我通过 fluent API 忽略了一个列,但想在使用某些逻辑执行存储过程时填充该属性。但它没有映射忽略的列属性。请让我知道是否有任何方法可以先在实体框架代码中执行此操作。

【问题讨论】:

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


    【解决方案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
    

    附:不要将 MyEntityBase 类标记为 ABSTRACT - EF 会将这种关系映射为数据库继承。

    【讨论】:

    • 感谢您的回复。我以类似的方式解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多