我有对象的基类所审核:EF代码优先映射复杂类型关系
AuditableObject
public class AuditableObject : DomainObject, IAuditable
{
... some fields
public AuditInfo AuditInfo
{
get;
set;
}
}
AuditInfo
public class AuditInfo : IAuditable
{
public int CreatedByDbId
{
get;
set;
}
public DateTime CreatedDate
{
get;
set;
}
public int? AmendedByDbId
{
get;
set;
}
public DateTime? AmendedDate
{
get;
set;
}
}
的CreatedByDbId和AmendedByDbId链接到SystemUser对象:
SystemUser
public class SystemUser
{
public int SystemUserDbId
{
get;
set;
}
public string Username
{
get;
set;
}
}
我有一个类呼叫从AuditableObject,其中也有其他SystemUser属性继承:
public class Call : AuditableObject
{
... some fields
public SystemUser TakenBy { get; set;}
public SystemUser CreatedBy { get; set; }
public SystemUser CancelledBy { get; set;}
public int CancelledByDbId {get; set;}
public int TakenByDbId { get; set;}
}
调用数据库表
CREATE TABLE [dbo].[Call](
[CallDbId] [int] IDENTITY(1,1) NOT NULL,
[CancelledBy] [int] NULL,
[CreatedByDbId] [int] NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[AmendedByDbId] [int] NULL,
[AmendedDate] [datetime] NULL,
[TakenBy] [int] NOT NULL)
我似乎无法获得我的映射,例如
modelBuilder.ComplexType<AuditInfo>();
...// configuration for Call
this.Property(x => x.AuditInfo.AmendedByDbId).HasColumnName("AmendedByDbId");
this.Property(x => x.AuditInfo.AmendedDate).HasColumnName("AmendedDate");
this.Property(x => x.AuditInfo.CreatedByDbId).HasColumnName("CreatedByDbId");
this.Property(x => x.AuditInfo.CreatedDate).HasColumnName("CreatedDate");
this.Property(t => t.CancelledByDbId).HasColumnName("CancelledBy");
this.Property(t => t.TakenByDbId).HasColumnName("TakenBy");
this.HasRequired(t => t.TakenBy).WithMany().HasForeignKey(x => x.TakenByDbId);
this.HasRequired(t => t.CancelledBy).WithMany().HasForeignKey(x => x.CancelledByDbId);
,我总是得到在运行时的错误,如:
Invalid column name 'SystemUser_SystemUserDbId'.
Invalid column name 'SystemUser_SystemUserDbId1'.
Invalid column name 'SystemUser_SystemUserDbId2'.
Invalid column name 'CreatedBy_SystemUserDbId'.
我无法弄清楚:(