Iam have some trouble for some time to figure out how to take data from a data table (MSSQL 2008). Problem is this. You have 3 tables:
- TABLE1 (Jobs): JobID, JobName
- TABLE2 (Worker): WorkerID, WorkerName
- TABLE3 (Worker2Job): RowID, WorkerID, JobID
I Assume that JOB can be done by many workers, so I need “Worker2Job” table. So I can type that JobID:1 is made by WorkerID1 and WorkerId2 etc…
Now using Entity framework I dont know how to fetch the “WorkerName” property for the first of worker (nor any other list of workers).
Any ideas ?!
Thx in advance!
You don’t need any special
RowIdinWorker2Job. Just define yourWorker2Jobwith only two columns:WorkerIdandJobIdand make both these columns composite primary key of the table. Once you add all three tables to the entity designer it will automatically see many-to-many relation and create only two entities with the correct relation in the model.Workerentity will haveJobsnavigation property andJobwill haveWorkersnavigation property. You will be able to write query like:Such query will load a job with all related workers and you will have access to their names.