c# - Linq to Sql - Populate JOIN result into a List -
I'm not sure this can be done, but this is the scenario.
I want to turn this SQL into the Linq:
SELECT * join the Department D INNER employee e.DepartmentID = d.DepartmentID
Department - Many relationships from employee 1.
I have created a custom object, which I want to populate the result in it.
Public Sector Departments Department (Department of Public Sector); Set; } Public List & amp; Staff; & Gt; Employee {receive; Set;}}
has come with this Linq I
var result = d to DBA. Join the department and in DBA Empire D. Department Id E. Is equal to. In the department I selected J1 new department auspicious (department = D, employee = J. 1.ToList ()};
I tried to do this and it is not working. Can someone shed some light on me? I want to make an internal conference between the department and the employee. For each department in the results, I want to create a department in which the department holds a list of employees related to that department. / P>
Linq provides an ad hoc solution for it or I should be repeated through it
thanks:
EDIT: This works for me as it seems
< Pre> var results = D from DBA. Join the Department and in DBA Empire D. Discrete ID equal E. Department Id in J1 where J. 1. Count ()> Select new departments Best wishes { Department = D, employee = J 1.ToList ()};
Looks like you're loading lazy?
DataLoadOptions dlo = New DataLoadOptions (); Dlo.LoadWith & lt; Department & gt; (D => d. Employee); (Var dba = new MyDataContext ()) using {dba.LoadOptions = dlo; Var result = d in db. Select department D; }
Now, if you do not have a relationship between the department and the employee (the Linq2Sql designer will do this for you, if you have the database relation setup) then you should consider doing this . All this makes dramatically easy. In fact, you do not even need your campaign summary.
Comments
Post a Comment