c# - EF does not include where clause -


i have small issue ef. i'm performing query on large table, , takes long. think found cause, cannot find solution;

my linq query looks this:

ienumerable<string> o = (from p in table p.itemid == itemid && p.imagesize == size select p.path); return o.any() ? o.firstordefault() : null; 

i expect produce sql query clause, produces this:

select  [extent1].[itemid] [itemid],  [extent1]......... snap 10 columns [dbo].[table] [extent1] 

the clause , select (i try select 1 column) executed after enumeration. want produce sql query clause , select 1 column.

what doing wrong?

since creating ienumerable<string> type of object, ef runs query in first line. any() or firstordefault() executed in memory set. if want "continue" writing linq statements , run query in end; go iqueryable<t>.

iqueryable<string> o = (from p in table p.itemid == itemid && p.imagesize == size select p.path); return o.singleordefault();    

but ryan bennett suggested, easier use;

return table.where(p => p.itemid == itemid && p.imagesize == size).singleordefault().path; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -