我有 2 个继承相同抽象类的实体。如何组织实体之间的一对一关系?
[Table("AbstractObjects")]
public abstract class AbstractObject{
public Guid Id{get;set;}
public string Name{get;set;}
public DateTime CreateDate{get;set;}
}
[Table("FolderObjects")]
public class Folder:AbstractObject{
public virtual Content Content{get;set;}
}
[Table("ContentObjects")]
public class Content:AbstractObject{
public virtual Folder Folder{get;set;}
}
标准解决方案工作不正常,它建立了一对多的关系
modelBuilder.Entity<Folder>()
.HasRequired(x => x.Content)
.WithRequiredDependent(c => c.Folder);