我想创建一个TPT映射,其中基类本身保存信息,派生类只是扩展它。
基本上,我有一个基类和一些派生类,我想知道如何处理它们的映射。这是一个荒谬简化的例子:
[Table("Task")]
public class Task : TaskBase
{
// No properties... This is just a "Task", not either an internal nor external one.
}
[Table("InternalTask")]
public class InternalTask : TaskBase
{
public int UserId { get; set; }
public virtual User User { get; set; }
}
[Table("ExternalTask")]
public class ExternalTask : TaskBase
{
public int CustomerId { get; set; }
public virtual Customer Customer { get; set; }
}
public abstract class TaskBase : Entity
{
/// <summary>Gets or sets the identifier of this item.</summary>
public int Id { get; set; }
[...]
public string Subject { get; set; }
public virtual User UserCompletedBy { get; set; }
public virtual User UserLockedBy { get; set; }
public virtual User UserOwner { get; set; }
public virtual ICollection<TaskBase> ChildTasks { get; set; }
public virtual ICollection<TaskAttachment> Attachments { get; set; }
}
现在,Entity Framework使用Customer_Id字段和User_Id字段生成一些奇怪的SQL模式,尽管我已正确指定它们(?)。 因此,我想知道这种模式的正确方法是什么。
谢谢!