Hi I have this bit of linq code
var fp = lnq.attaches.First(a => a.sysid == sysid).name;
When profiled it generates the following t-sql
Project to the name
property before using First()
:
var fp = lnq.attaches.Where(a => a.sysid == sysid)
.Select(a => a.name)
.First();
This doesn't change the use of an index though - for that your Where
clause is responsible (in your initial query the lambda you passed to First()
). Both queries benefit from an index on the name
column, the second one is just faster because only one column value has to be materialized.