我与以下对象一对一关系:
[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]
public class Project : AuditInfoComplete
{
[Key]
[DataMember]
public Guid ProjectId { get; set; }
[DataMember]
public virtual Ecwid Ecwid { get; set; }
}
在DbContext中我有:
modelBuilder.Entity<Ecwid>().HasKey(p => p.ProjectId);
modelBuilder.Entity<Project>().HasOptional(p => p.Ecwid).WithRequired(p => p.Project);
问题:当我创建Project时,Entity Framework在数据库中创建Ecwid对象,但我不需要这个对象。在DbContext中我添加了“HasOptional”,为什么EF为我创建了Ecwid对象?