I'm using EF Code first and want to create such structure for example:
- There is "Invoice" model
- And also we have other entities like Client, Customer, etc that may have a list of Invoices
basically the relation is one to many. One invoice can belong only to a Client, or a Customer, etc
I want to store all invoices in the same table since is the same model for all, and using fluent api want to create the relation tables
something like this below is for many to many:
modelBuilder.Entity<Client>()
.HasMany(c => c.Invoice).WithMany(i => Clients)
.Map(t => t.MapLeftKey("ClientID")
.MapRightKey("InvoiceID")
.ToTable("ClientInvoices"));
modelBuilder.Entity<Customer>()
.HasMany(c => c.Invoice).WithMany(i => Customer)
.Map(t => t.MapLeftKey("CustomerID")
.MapRightKey("InvoiceID")
.ToTable("CustomerInvoices"));
How can i do that for one to many ? How to have 2 tables where to store the ClientInvoices , CustomerInvoices ?