Filling an EntityCollection with an arbitrary query the same FetchEntityCollection does

Posts   
 
    
acl
User
Posts: 92
Joined: 28-Mar-2012
# Posted on: 28-Mar-2012 12:29:01   

Hi,

in the following section of the documentation, http://www.llblgen.com/documentation/3.1/LLBLGen%20Pro%20RTF/hh_goto.htm#Using%20the%20generated%20code/Adapter/gencode_datareadersprojections_adapter.htm#projectingproconentities, a new DataProjectorToIEntityCollection2() is used to fill an EntityCollection with a stored procedure.

I get this to work on my end using an arbitrary query rather than a stored procedure. I have two questions:

First, it is very cumbersome to have to declare all the fields in the valueProjectors. Is this really necessary? The generated code already contains all this information; so I would expect there to be some function in the generated code which does this for me.

Second, and more importantly, why it is that all entities have IsNew set to true after fetching. At least in my case that's incorrect, since they were just fetched from the DB..

What I'd like is that the EntityCollection produced by the DataProjectorToIEntityCollection2 is identical to one that is fetched using FetchEntityCollection() with an include field list (the fields specified in the value projectors). Can this be accomplished?

Thanks,

andreas

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Mar-2012 16:52:30   

Usually projections are used to project a resultSet of complex queries into fields of entities. So usually you need to define which resultSet fields map to which entity fields.

acl
User
Posts: 92
Joined: 28-Mar-2012
# Posted on: 28-Mar-2012 17:06:58   

Alright; but what about my second question.

Is it possible to fetch an EntityCollection using DataProjectorToIEntityCollection2 which is identical to one that is fetched using FetchEntityCollection() with an include field list (the fields specified in the value projectors). Can this be accomplished?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Mar-2012 18:11:17   

Can you suggest a business case, why this is needed over fetching an EntityCollection?

acl
User
Posts: 92
Joined: 28-Mar-2012
# Posted on: 29-Mar-2012 07:57:32   

Sometimes queries can get really complex, and then it is often easier to use plain SQL to express them.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 29-Mar-2012 11:26:56   

acl wrote:

Alright; but what about my second question.

Is it possible to fetch an EntityCollection using DataProjectorToIEntityCollection2 which is identical to one that is fetched using FetchEntityCollection() with an include field list (the fields specified in the value projectors). Can this be accomplished?

What does that mean exactly: 'with an include field list'... ? A projection projects the result of a query, so the query is produced somehow and you define the projection. The easiest is to use queryspec for this (new in v3.5). If you want our lowlevel api, you have to specify the projections, how else does the system know what to project to what field?

Frans Bouma | Lead developer LLBLGen Pro
acl
User
Posts: 92
Joined: 28-Mar-2012
# Posted on: 29-Mar-2012 12:05:38   

Please ignore my first question about having to specify the fields in the valueProjectors.

Sorry the second question was not formulated clearly enough. What I meant is the following.

It is possible to fetch an EntityCollection with an include fields list. So the EntityCollection has a way of knowing which fields were fetched (e.g., when saving it later it won't replace unfetched elements with some kind of default value).

Now when I create an EntityCollection using DataProjectorToIEntityCollection2, I similarly specify certain fields to be selected (first as part of the select query, and second as part of the value projectors).

Therefore, I was expecting that creating an EntityCollection using DataProjectorToIEntityCollection2 would be equivalent to adapter.FetchEntityCollection.

However, this is not the case. Most obviously, the .IsNew Flags of the entities are set to True when fetched using DataProjectorToIEntityCollection2 and set to false when fetched using adapter.FetchEntityCollection.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Mar-2012 22:27:58   

If you don't include the fields in the projector then the fields are not set. As they are not set, the DBValue and CurrentValue are equal, so they are not detected as Changed, thus they won't be included in any updates. So you don't have to worry about that. That is also the way IncludeFields works with FetchEntityCollection, the include list is not kept in the collection is just that the current value and dbvalue are not set.

With the IsNew is different, the projector doesn't set that, neither the entity is marked as Fetched status. If you want that you can make your own projector, just download the source code and copy the DataProjectorToEntityCollection class and make your own.

David Elizondo | LLBLGen Support Team