entityset vs list query opening linq2sql
in linq sql class, since properties combined unfamiliar keys entityset objects, exercise ienumerable, where objects datacontext table objects exercise iqueryable?
edit: clarify, here an instance illustrates i'm perplexing understand. example:
ctx.matches.where(x => x.matchid == 1).single()
.matchplayers.max(x => x.score);
hits database twice where as:
ctx.matchplayers.where(x => x.matchid == 1)
.max(x => x.score);
only runs 1 query. here traces:
exec sp_executesql n'select [t0].[matchid], [t0].[date]
from [dbo].[matches] [t0]
where [t0].[matchid] = @p0',n'@p0 int',@p0=1
go
exec sp_executesql n'select [t0].[matchid], [t0].[playerid], [t0].[score]
from [dbo].[matchplayers] [t0]
where [t0].[matchid] = @p0',n'@p0 int',@p0=1
go
and
exec sp_executesql n'select max([t0].[score]) [value]
from [dbo].[matchplayers] [t0]
where [t0].[matchid] = @p0',n'@p0 int',@p0=1
go
which also shows that, even worse, max finished during c# turn rather database.
i know reason happens inadequacy between iqueryables ienumerables, since doesn't matchplayers vigilant initial instance exercise iqueryable interface same advantages latter example.
Comments
Post a Comment