1

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

Public Class Audit
    Public Property CreatedOn as DateTime
End Class

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

1 回答 1

0

可以先试试 Code First 的 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; }
}
于 2015-11-25T03:36:35.593 回答