1
votes

I have problem when I try to migrate my model in EF Core 2.0.

public class Profile
{
    [Key]
    public Guid Id { get; set; }

    public Guid UserId { get; set; }
    public ExternalUser User { get; set; }
}

public class OrganizationCustomerProfile : Profile
{
    public string CompanyName { get; set; }

    public Address LegalAddress { get; set; }
    public Address ActualAddress { get; set; }

    public BusinessRequisites Requisites { get; set; }

    public string President { get; set; }

    public IEnumerable<ContactPerson> ContactPerson { get; set; }
}

public class PersonCustomerProfile : Profile
{
    public FullName Person { get; set; }

    public Address Address { get; set; }
    public string PhoneNumber { get; set; }
}

public class ContactPerson
{
    [Key]
    public Guid Id { get; set; }

    public FullName Person { get; set; }

    public string Rank { get; set; }
    public string Email { get; set; }
    public string PhoneNumber { get; set; }

    public Guid ProfileId { get; set; }
    public Profile Profile { get; set; }
}

Here I want to add complex datatypes Address and BusinessRequisites, which are:

public class BusinessRequisites
{
    public string OGRN { get; set; }
    public string INN { get; set; }
    public string KPPCode { get; set; }

    public string SettlementAccount { get; set; }

    public string RCBIC { get; set; }

    public string CorrespondentAccount { get; set; }

    public string BankName { get; set; }
}

public class Address
{
    public string FullAddress { get; set; }

    public float Latitude { get; set; } 
    public float Longtitude { get; set; }
}

Code which I use for TPH binding:

public DbSet<Profile> UserProfiles { get; set; }
public DbSet<ContactPerson> ContactPerson { get; set; }
public DbSet<OrganizationCustomerProfile> OrganizationCustomerProfile { get; set; }

...

modelBuilder.Entity<Profile>().HasKey(u => u.Id);

modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.ActualAddress);
modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.LegalAddress);
modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.Requisites);

But when I try to make a migration, I get an error:

"Cannot use table 'UserProfiles' for entity type 'OrganizationCustomerProfile.ActualAddress#Address' since it has a relationship to a derived entity type 'OrganizationCustomerProfile'. Either point the relationship to the base type 'Profile' or map 'OrganizationCustomerProfile.ActualAddress#Address' to a different table."

So, what the reason of this error? Is it not possible to create hierarchy inheritance in EF Core 2.0?

Thank you!

1

1 Answers

1
votes