简体   繁体   中英

EntityFramework custom many to many without navigation property

I want to do many-to-many relation between these objects:

class Flyer { 
     Guid Id; 
     virtual ICollection<Address> Stores; 
}

And:

class Address {
     Guid Id;
 }

Of course these models are simplified.

And I do not want a navigation property to Flyer inside Address because Address is in relation with other objects too. It is possible?

Fluent API only

How are you identifying what the address belongs to if it can belong to multiple different tables? Do you have a Join table? Like a AddressToFlyer Table that establishes the relationship between the two tables?

When I have complex queries that need to take place like this where one table can be used by many tables, I create join tables and typically create views that handle the joins and give me the data what I want so I can just do a select in Entity Framework and not worry about the Navigational property, then implement said view in Entity framework like you would a regular table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM