Linq-to-Sql Count -


i need count on items in joined result set condition true. have "from join where" type of expression. expression must end select or groupby. not need column data , figure faster not select it:

count = (from e in dc.entries select new {}).count(); 

i have 2 questions:

  1. is there faster way in terms of db load?
  2. i have duplicate entire copy of query. there way structure query can have 1 place both counts , getting list fields?

thanks.

please pay especial attention:

  1. the query join , not simple table must use select statement.
  2. i need 2 different query bodies because not need load actual fields count list.

i assume when use select query filling data when use query.count vs table.count. forward understand i'm asking possible better ways , detailed knowledge of happens. need pull out logging deeper.

queryable.count

the query behavior occurs result of executing expression tree represents calling count(iqueryable) depends on implementation of type of source parameter. expected behavior counts number of items in source.

in fact, if use linqtosql or linqtoentities, queryable.count() sent database. no columns loaded memory. check generated sql confirm.


i assume when use select query filling data when use query.count vs table.count

this not true. check generated sql confirm.


i have duplicate entire copy of query. there way structure query can have 1 place both counts , getting list fields

if need both count , list, list , count it.

if need count , other times need list... write method returns complex iqueryable, , call .count() , other times call .tolist();


i not need column data , figure faster not select it.

this false in scenario. can true in scenario index covers result columns, don't have result columns.

in scenario, whatever index chosen query optimizer, index can used make count.

sum up: query optimizer perform optimization desire.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -