i created a db-model with the entity framework wizzard in Visual Studio. There are 2 tables (job, stocktype) which are related to each other with the table stocktype2job.

Job <------- no direct relation / navigation property --------> StockType
| |
| |
---------------------> StockType2Job ----------------------------->
With a Job Object, i could do something like this …
EntitiesObject db = new EntitiesObject();
Job job = db.Jobs.SingleOrDefault(j => j.IdJob == 40);
List<StockType> stockTypes = new List<StockType>;
foreach (StockType2Job st2j in job.StockType2Jobs)
{
stockTypes.add(st2j.StockType);
}
That should work just fine. But is there a way to create a navigation property in the job entity so i can write something like this?
EntitiesObject db = new EntitiesObject();
Job job = db.Jobs.SingleOrDefault(j => j.IdJob == 40);
List<StockType> stockTypes = job.StockTypes; // <<-----
Thanks for your kind Help
Apo
It is clear (from the self reference) that
StockType2Jobsdoes not only contain foreign keys to StockType and Job, so you can’t map a many-many relationship with a navigation propertyjob.StockTypes. So you can’t do anything else then collectingStockTypeviajob.StockType2Jobs. But that’s not a big deal:You might get tempted to wrap this in an unmapped property
job.StockTypes, but usually it’s not a good idea to do this.