I'm designing an invoice class. To put it simple:
- I'm using EF 6 code-first with Fluent-API.
- The tables(classes): Invoice, Supplier, Customer, Store
The invoice class has an issuer and an addressee. I want something like 'IssuerId' and 'AddresseeId'
The issuer could be either the supplier (for buying items) or the store (for selling/returing items) and the addressee could be either the supplier (for returning items), the customer (for selling items) or the store (for buying items).
Of course I don't want to create FK collumns for each one of 'em, beacause only two would be used for each invoice and the others would be null.
The problem as explained: The addressee and the issuer could be any of those tables for each invoice.
I thought adding an enum as a discriminator to tell EF which table my FK is pointing to:
public int AdresseeId { get; set; }
public AdresseeType AdresseeType { get; set; } // 'C' is customer, 'S' is supplier...
But I need the relationships to work and navigation properties too. I'm trying to find the most clean solution for this case. Any help would be much appreciated. Thanks.