Composite Projection from EntityCollection

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 14-Nov-2007 17:04:32   

Imagine that I have a CustomerEntity and customer has 1:N Orders. I can fetch an EntityCollection<CustomerEntity> and project the results onto DTO.Customer.

Assume that when EntityCollection<CustomerEntity> is fetched, the collection is fetched with a prefetch to fill the Orders member of CustomerEntity.

In a single operation, can I also project the CustomerEntity.Orders entity collection onto DTO.Order, OR do I need to iterate the CustomerEntity entity collection and build my DTOs accordingly?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Nov-2007 17:12:07   

You can project a graph into a dataSet. Please refer to Hierarchical projections of entity collections in the LLBLGen Pro manual, under "Using the generated code -> SelfServicing/Adapter -> Using the entity collection classes".

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 14-Nov-2007 19:05:52   

I have reviewed the topic: "Hierarchical projections of entity collections", this is a cool approach, but having an untyped data set in my MessageContract is unacceptable.

My MessageContracts will be published and consumers of my services need to know the schema of the data being passed between endpoints, therefore I need to pass typed objects as DTOs.

Can I project a hierarchy onto custom classes?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Nov-2007 10:41:54   

Can I project a hierarchy onto custom classes?

No, there is no built-in way for doing this. I'm afraid you'd have to do it manually.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Nov-2007 11:26:37   

Indeed. In v2.6, a hierarchical projection of multiple fetches to custom classes will be added, so you can fetch customers, orders, orderdetails for example in 3 queries (using Linq, or a prefetch path) and project each set onto custom classes.

The biggest hurdle is merging the sets. The raw logic is already implemented for prefetch paths, it's just that it's not available in such a form that you can use it for other code than prefetch paths.

To project the object graph onto sets per type can be done on custom classes, though it requires some manual code. The meat is already done for you, so it's rather easy. What you should call first is ObjectGraphUtils.ProduceCollectionsPerTypeFromGraph(collection), to get a dictionary with per type the entities in a collection. From there, you can project each collection onto custom classes using your own projection code. For the fine print, see EntityCollectionBase2.CreateHierarchicalProjection()'s code for ideas.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 15-Nov-2007 19:09:08   

Ok cool. Thanks, I will have a go at it.