1

I have the following situation:

I have a table 'Product' which has

Id | Name

Then I have another table Product_Vendor which has

Id | Product_Id | Vendor_Id

where Product_Id is a foreign key to Product.Id. Now in my Entity class code, I want the Product entity to have a property

List<Guid> Vendors { get; set; }

Which contains all the Vendor_Id's that corresponds with the Product_id in Product_Vendor. The thing is, the Vendor_Id is a Guid that comes from a table that is in another database so it technically is not a foreign key, just a uniqueidentifier field with no constraints.

How can I map this using fluent api mapping in my ProductEntity EntityConfiguration? I use C# and SQL. I hope this is a bit clear, more information can be provided if needed :-)

Jelle Capenberghs
  • 794
  • 2
  • 14
  • 30
  • Possible duplicate of [How can I get a list of linked 1-n elements?](https://stackoverflow.com/questions/50447212/how-can-i-get-a-list-of-linked-1-n-elements) – Michał Turczyn May 25 '18 at 09:36
  • I could copy and paste my answer from above SO post :) – Michał Turczyn May 25 '18 at 09:37
  • You can map a Many to Many property using the Fluent API as can be seen in this answer https://stackoverflow.com/a/8927446/6787641 – Chris Terry May 25 '18 at 09:20
  • You might want to look at this answer here. Essentially what you want is a many-many mapping https://stackoverflow.com/a/8927446/6787641 – Chris Terry May 25 '18 at 10:42
  • I did provide this as an answer, but the SO mafia decided I was being far too helpful:) – Chris Terry May 25 '18 at 10:42
  • Thanks for the help guys, but as the Vendor table is in another database a normal many-to-many mapping is not possible here. But I guess what I need to do isn't really possible since it technically isn't a relational mapping but rather a query. – Jelle Capenberghs May 25 '18 at 11:02
  • 1
    You might be able to do something with a stored procedure, perform the linking inside the stored procedure – Chris Terry May 25 '18 at 11:32

0 Answers0