c# - LINQ Method that returns set based on filtered sub-set -


I have 2 tables with a unit of 1, one per line Another bus is the mapping table of my Entity ID and EmployerID. I am trying to write a LINQ method which returns all the units back from the first table where the anti-id is in the mapping table that is filtered by the employee.

Simplified table structure example TaskTable: id, description, status TaskViewTable: ID, TaskID, EmployeeID

I want to return all the rows where the ID is based on the TaskViewTable subQuery results in the employee.

Any help in doing this in LINQ? I have set up between two tables of 1, I know that there are such questions, maybe I am dense, but I think what I was asking was not fully implemented for them. (For example)

Unfortunately, I forgot to show what I am still doing: IQueryable & lt; TblTask ​​& gt; TTask = context.GetTable & LT; TblTask ​​& gt; (); Return TTSK Where (T = & gt; T.B.BTSS.S view where (V = & gt; v.EmployeeID == empID))

This, however, does not like my with a unknown method (?)

Something like this should do the trick:

  var function = tTask.Where (t = & gt; tTaskView.Where (v = & gt; v .id == empId). (V = & gt; v. TaskId) .Contains (t.id));   

You can split up into two sections:

  // 1) Get all work views for employee IDs and only mapped Select TaskID var TaskViews = tTaskView.Where (V => v.id == empId). Select (V => v.TaskId); // Taskwuce = INIMABLE & Lt; Int & gt; // 2.) then get all the functions from the filtered task id vork tasks = tTask.Where (t = & gt; taskViews.Contains (t.id));   

UPDATE

  // 3) Project filtered results have been changed to IEnumerable & lt; Work & gt; Return function. Select (t = & gt; new task () {id = tiid, actionable = t. Actionable, statusID = t. stattis id, type id = t type, id = description.}};   

You can of course do everything in a good one-liner:

  Public listing & tasks; Tasks; GetTasks (int empId) {Return TTSK. = & Gt; TTSKView.Where (V = & gt; v.ID == empId). Select (V => v.TaskId) contains (TIID)). (T => New task () {ID = t.ID, ActionableID = t.Actionab LeID, StatusID = t.StatusID, TypeID = t.TypeID, Description = t.Description}). ToList ();}    

Comments