Tuesday, 15 May 2012

Compound "from" clause in Linq query in Entity Framework -



Compound "from" clause in Linq query in Entity Framework -

i've been working entity framework few weeks now. have been working linq-objects , linq-sql years. lot of times, write linq statements this:

from pupil in db.students score in student.scores score > 90 select student;

with other forms of linq, returns distinct students have @ to the lowest degree 1 score greater 90. however, in ef query returns 1 pupil every score greater 90.

does know if behavior can replicated in unit tests? possible bug in ef?

i don't sql-like syntax (i have no improve name it), when start nesting them.

var students = db.students.where(student => student.scores.any(score => score > 90) ) .tolist();

this snippet, using method syntax, same thing. find far more readable. it's more explicit in order of operations used.

and far have experienced, ef hasn't yet shown bug selection using method syntax.

edit

to reply problem:

however, in ef query returns 1 pupil every score greater 90.

i think is due bring together statement used in final sql run. why avoid sql-like syntax, because becomes hard differentiate between want retrieve (students) , want filter with (scores).

much in sql, joining info students , scores, , running filtering operation on collection. becomes harder unseparate result 1 time again collection of students. think main cause of issue. it's not bug per sé, think ef can handle 1 way.

alternative solutions above:

if returns 1 pupil per score on 90, take distinct students returned. should same result set. use more explicit parentheses () , formatting nest separate sql-like statements.

note: i'm not saying can't done sql-like syntax. aware of reply sentiment based.

linq entity-framework

No comments:

Post a Comment