hello, can you help me how to write Linq query (using Entity Framework) for the following requirements:
I have tables:
User(ID, Name),
Checklist(ID, Name, UserID(NOT NULL))
Job(ID, Name, UserID(NOT NULL))
Task(ID, Name, JobID(NULLABLE), UserID(NULLABLE), ChecklistID(NULLABLE)),
In the Task table there is always only one of foreign keys filled (others are NULL):
Task data example:
ID Name JobID UserID ChecklistID
1 T1 1 NULL NULL
2 T2 NULL 1 NULL
3 T3 NULL NULL 1
…
I want to select all tasks for the user based on the following rules:
1. all tasks belonging to user (UserID is filled)
2. all tasks which are related to job (JobID is filled) and Job is owned by the user
3. all tasks which are related to Checklist (ChecklistID is filled) and Checklist is owned by the user
4. ID of the user is input parameter
I want to get result in one Linq query. I’m beginner in Linq and I have no idea how to do it correctly.
thanks a lot for your help.
This appears to be what you’re trying to get. You may have to add in “DataContext.” before the table names.