问题
I want to create a TPT mapping where the base class itself holds information and the derived classes just extend it.
Basically, I've got a base class, and a few derived classes, and I'm wondering how to handle their mapping. Here's a ridiculously simplified example:
[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; }
}
Now Entity Framework generates some weird SQL schema with Customer_Id fields and User_Id fields, although I've specified them correctly(?). Hence I was wondering what the correct approach for such a schema is.
Thank you!
来源:https://stackoverflow.com/questions/36202178/tpt-inheritance-with-non-abstract-base-class-in-code-first