Tôi đang cố gắng sử dụng di chuyển EF7 và bị kẹt khi tôi mô hình hóa mô hình Tổ chức có kế thừa.Chuyển đổi EF7 - Loại CLR tương ứng cho loại thực thể '' không phải là tức thời
Tổ chức là lớp trừu tượng và có hai lớp cụ thể kế thừa nó được gọi là Cá nhân và Công ty.
Tôi đặt lớp trừu tượng Tổ chức là DbSet trong DbContext và chạy di chuyển.
Tôi đang theo hướng dẫn này here
Các lỗi sau đây được hiển thị:
Loại CLR tương ứng cho loại hình tổ chức 'Tổ chức' không instantiable và không có loại thực thể có nguồn gốc trong mô hình đó tương ứng với loại CLR cụ thể.
Tôi nên làm gì?
EDIT - Cập nhật với mã
Tổ chức
public abstract class Organization
{
public Organization()
{
ChildOrganizations = new HashSet<Organization>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public bool Enabled { get; set; }
public bool PaymentNode { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
// virtual
public virtual ICollection<Organization> ChildOrganizations { get; set; }
}
cá nhân
public class Individual : Organization
{
public string SocialSecurityNumber { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
Công ty
public class Company : Organization
{
public string Name { get; set; }
public string OrganizationNumber { get; set; }
}
DbContext
public class CoreDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Organization> Organization { get; set; }
public CoreDbContext(DbContextOptions<CoreDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
Cảm ơn trước!
hãy thêm mã trong câu hỏi. –
Bạn có DbContext trong cùng một dự án hoặc trong một dự án riêng biệt? –
@TomDroste DbContext nằm trong cùng một dự án thư viện lớp vì các mô hình miền và di chuyển nằm trong dự án web. – Rovdjuret