我有2个对象,它们以一对一的关系绑定到3-d:
public class Project : AuditInfoComplete
{
[Key]
[DataMember]
public Guid ProjectId { get; set; }
[DataMember]
public virtual Ecwid Ecwid { get; set; }
[DataMember]
public virtual ProjectDomain ProjectDomain { get; set; }
}
[DataContract(IsReference = true)]
public class Ecwid
{
[Key, ForeignKey("Project")]
[DataMember]
public Guid ProjectId { get; set; }
[DataMember]
public string EcwidShopID { get; set; }
public virtual Project Project { get; set; }
}
[DataContract(IsReference = true)]
public class ProjectDomain
{
[Key, ForeignKey("Project")]
public Guid ProjectId { get; set; }
[DataMember]
public string Domain { get; set; }
public virtual Project Project { get; set; }
}
在DbContext中我有这个:
modelBuilder.Entity<Ecwid>().HasKey(p => p.ProjectId);
modelBuilder.Entity<Project>().HasOptional(p => p.Ecwid).WithRequired(p => p.Project).WillCascadeOnDelete();
modelBuilder.Entity<ProjectDomain>().HasKey(p => p.ProjectId);
modelBuilder.Entity<Project>().HasOptional(p => p.ProjectDomain).WithRequired(p => p.Project).WillCascadeOnDelete();
当我创建Project时 - 在数据库中为我自动创建“Ecwid”对象,但“Project Domain”对象没有创建。为什么行为不同?