Today I ran into something a bit weird.
I used mini-profiler to see the SQL queries executed.
It seems that when using obj.Children.Select(x => x.Prop1).SingleOrDefault() the query executed get ALL columns.
However, using ctx.Children.Select(x => x.Prop1 && x.IDParent == idObj).SingleOrDefault() gets only Prop1.
Any idea why the difference?
Because the first query gets executed here:
And the second query gets excuted here:
You get the first query for the full entity with all columns because the navigation property gets loaded due to lazy loading. After the entity is loaded your
Selectwill be applied in memory. The database query is already finished at this point when you project to the single property.The second query performs the projection (selecting a single column) really in the database and does not load more than this column.