【问题标题】:Entities Framework 4 Code First: Inheritance实体框架 4 代码优先:继承
【发布时间】:2015-11-25 11:36:35
【问题描述】:

我目前正在试用 EF4 代码优先。我的 POCO 类继承自包含 CreatedBy、CreatedOn、UpdatedBy、UpdatedOn 的 Audit 类。我希望框架在创建数据库时将审核属性包含在我的操作表中,但事实并非如此。有谁知道如何在不覆盖 OnModelCreating() 方法的情况下启用此功能?

Public Class Audit
    Public Property CreatedOn as DateTime
End Class

Public Class Action
    inherits Audit
    Public Property ActionId As Int32
End Class

【问题讨论】:

    标签: asp.net entity-framework code-first


    【解决方案1】:

    你可以先试试Code的ComplexType,如下,我觉得对OOD比较好

    [ComplexType]
    public class CreateType
    {
        public DateTime CreateOn { get; set; }
    
    
        public string CreateBy { get; set; }
    
        ...
    }
    
    public class Action
    {
        public int ActionId { get; set; }
    
        public CreateType CreateType { get; set; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多