V
V
Vladimir Kovalev2018-01-04 09:42:37
Entity Framework
Vladimir Kovalev, 2018-01-04 09:42:37

fluent api. How to disable TPH? Why is EF trying to find a field that doesn't exist in the entity?

Help. How to disable TPH, or rather, so that EF does not require the creation of the Discriminator field? And can you explain why FE is looking for a field (in my case it is supplier_Id) that does not exist in the entity?
Essence

public class Supplier
    {
        public int Id { get; set; }
        public int companyId { get; set; }
        public virtual Company Company { get; set; }
}

Configuration
public class SupplierConfiguration : EntityTypeConfiguration<Supplier>
    {
        public SupplierConfiguration()
        {
            ToTable("suppliers");
            HasKey<int>(s => s.Id);
            Property(s => s.companyId).HasColumnName("companyid").IsRequired();
            HasRequired(s => s.Company).WithMany().HasForeignKey(s => s.companyId);
        }
    }

Context
protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Configurations.Add(new SupplierConfiguration());
            modelBuilder.Configurations.Add(new CompanyConfiguration());
            modelBuilder.Configurations.Add(new CountryConfiguration());
            base.OnModelCreating(modelBuilder);
        }

Thanks in advance =)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question