Answer the question
In order to leave comments, you need to log in
How to make the TPT approach through the Fluent API when inheriting from a generic class?
Hello connoisseurs. I will describe the point. There are several service types (Service.cs, ServiceMeetGuest.cs) and ticket types (Bid.cs, BidMeetGuest.cs). With migrations in service types, everything is simple.
But the types of requests are inherited from the generalized class, the type of service is indicated in the generalized type TService. I tried to do it this way:
There is a generalized class:
public class BidBase<TService>
{
public long Id { get; set; }
...
[ForeignKey("Service")]
[Required]
public long ServiceId { get; set; }
public virtual TService Service { get; set; }
}
public DbSet<BidBase<Service>> Bids { get; set; }
public DbSet<BidBase<ServiceMeetGuest>> BidsMeetGuest { get; set; }
public class Bid : BidBase<Service> { }
public class BidMeetGuest : BidBase<ServiceMeetGuest> {}
public DbSet<Bid> Bids { get; set; }
public DbSet<BidMeetGuest> BidsMeetGuest { get; set; }
Answer the question
In order to leave comments, you need to log in
You basically have THREE different types.
Since your BidBase does not participate as a separate DbSet (and, accordingly, there is no table for it), EF thinks that these are just two separate tables, the structure of which needs to be mapped one-to-one into separate tables
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question