o3h
asked on
Different Linq synatx for this expression
Hi I wonder how you make this Linq expression:
DataContext.GetObjectConte xt().Compa ny.Where(i => i.Id == selectedAssignmentID).Sele ctMany(i => i.ReferencePersons).ToList <Reference Person>();
Into from iin DataContext.GetObjectConte xt().Compa ny .....................
I just cant figure out how to use Selectmany with the other syntax. Thx
DataContext.GetObjectConte
Into from iin DataContext.GetObjectConte
I just cant figure out how to use Selectmany with the other syntax. Thx
Hi,
Linq SelectMany is equivalent to multiple from statements in the syntax sugared Linq style.
e.g.
from a in DataA
from b in DataB
select new {a.Prop, b.Prop}
Not sure of your precise data schema but I hope this helps.
Linq SelectMany is equivalent to multiple from statements in the syntax sugared Linq style.
e.g.
from a in DataA
from b in DataB
select new {a.Prop, b.Prop}
Not sure of your precise data schema but I hope this helps.
ASKER
I want the exact same behavior as the first line. Im just curious how your write in the following "syntax":
from comp in DataContext.GetObjectConte xt().Compa ny
where comp.Id == selectedAssignmentID
select comp.ReferencePersons..... .......... ...... (some selectmany stuff)
Sorry if I was unclear.
from comp in DataContext.GetObjectConte
where comp.Id == selectedAssignmentID
select comp.ReferencePersons.....
Sorry if I was unclear.
from comp in DataContext.GetObjectConte xt().Compa ny
where comp.Id == selectedAssignmentID
select comp.ReferencePersons
Is the same as
DataContext.GetObjectConte xt().Compa ny.Where(i => i.Id == selectedAssignmentID).Refe rencePerso ns
where comp.Id == selectedAssignmentID
select comp.ReferencePersons
Is the same as
DataContext.GetObjectConte
ASKER
Yes but how do i Do SelectMany?
So the following would be valid:
List<ReferencePerson> referencePersons = (from comp in DataContext.GetObjectConte xt().Compa ny
where comp.Id == selectedAssignmentID
select comp.ReferencePersons).... ......... (some extra?)
So the following would be valid:
List<ReferencePerson> referencePersons = (from comp in DataContext.GetObjectConte
where comp.Id == selectedAssignmentID
select comp.ReferencePersons)....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I do not know what do you mean with "select many".
This will return you a list of elements of ReferencePerson class with all it's data and fields loaded into each one of the list's elements:
List<ReferencePerson> referencePersons = DataContext.GetObjectConte xt().Compa ny.Where(i => i.Id == selectedAssignmentID).Refe rencePerso ns
Maybe if you tell us what fields/data/info are you trying to reach we can offer you a solution/alternative.
This will return you a list of elements of ReferencePerson class with all it's data and fields loaded into each one of the list's elements:
List<ReferencePerson> referencePersons = DataContext.GetObjectConte
Maybe if you tell us what fields/data/info are you trying to reach we can offer you a solution/alternative.
What I usually do for this situations is use direct one to many linking:
DataContext.GetObjectConte
I use to stablish database relationships between my tables, so:
DataContext.GetObjectConte
will return a list of those Companies that matches the idAssignment expression.
As a company can have many reference persons and I have a database relationship that stablish this on my Linq generated data model
DataContext.GetObjectConte
will directly return the list of reference persons of all companies that matches the where clause.
Without direct relationships on database I usually use joins to achieve this effect, never tried before with selectMany.