What does Query Projection mean in Entity Framework?

entity-framework

Question

I'm attempting to figure out what "Query Projection" exactly means when using LINQ to Entities or EntitySQL by studying several EF examples. Though I'm not 100% certain, I think that happens when the search results are filtered and projected into an anonymous type.

Could someone kindly clarify this and maybe provide a brief L2E question that utilizes an example?

1
24
10/18/2019 2:04:35 PM

Accepted Answer

When a query's result is sent to a type other than the one being questioned, this is called projection. It was described as: One more article the procedure for altering search results

Projection may be made to a concrete type or an anonymous type. It is comparable to the columns mentioned in your database if you are from the SQL world.SELECT clause.

Choosing a subset of an object to fit into a concrete type, as an example:

ParentObj.Select(x=> new ParentSlim { ParentID = x.ParentID,  Name = x.Name } );

.
Object merging into a third anonymous type example:
Recall: theselect new The projection is a chunk.

from P in ParentObj.AsQueryable()
join C in ChildObj.AsQueryable() on P.ParentID == C.ParentID

select new {                              // <-- look ma, i'm projecting!
               ParentID = P.ParentID,
               Name     = P.Name,
               SubName  = C.Name
               RandomDate = DateTime.UtcNow()
         }
28
6/1/2012 10:07:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow