GetRelationInfo with new Entities in v5.6

Posts   
 
    
Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 18-Feb-2020 11:16:51   

Lets say, I have this code:


var auftragErledigt = new AuftraegeErledigtPositionEntity();
            using (DataAccessAdapter daa = DataAccessAdapter.GetCUPnew())
            {
                daa.FetchEntityCollection(auftragErledigt.FlexStoxes, auftragErledigt.GetRelationInfoFlexStoxes());
            }

AuftraegeErledigtPositionEntity can have multiple Flexstoxes. The primary key of the positions is int. But there are also Flexstoxes, which have no position and its ForeignKeyColumn is null.

In v4.2 when the query is executed for a new Entity, the query is (simplified):


exec sp_executesql N'SELECT [DEV_CUPNEW_HEUTE].[dbo].[tblFlexstox].*  WHERE ( [DEV_CUPNEW_HEUTE].[dbo].[tblFlexstox].[AuftragErledigtPositionsID] = @p1)',N'@p1 int',@p1=0

In v5.6 it executes:

SELECT [DEV_CUPNEW_HEUTE].[dbo].[tblFlexstox].* WHERE ( [DEV_CUPNEW_HEUTE].[dbo].[tblFlexstox].[AuftragErledigtPositionsID] IS NULL)

Is it possible to get the old behaviour back, so, if it is a non nullable value/primary key, the value to load the flexes is 0?

Background:

We are using such queries a lot and in v4.2 we fetched then no entry. In v5.6 it fetches all entries, where foreign key is null and these are the wrong ones.

I know, we should not execute the query, if the entity is new, but it's not possible to find and change every line of code, this is done.

Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 18-Feb-2020 13:03:29   

I replaced GetRelationInfo* in entityIncludeAdapter.template with the old one (from v4.2) and the test was positiv.

But, is there a better way or maybe could it lead to some other errors?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 18-Feb-2020 17:05:27   

It's best not to change these templates, and I think in v4.2 the pk value was 0 by default but in 5.6 it's not set, so null, so you get a null predicate. I think setting the PK of auftragErledigt to 0 should fix it. That, or simply:

using (DataAccessAdapter daa = DataAccessAdapter.GetCUPnew())
{
    daa.FetchEntityCollection(auftragErledigt.FlexStoxes, 
            new RelationPredicateBucket(FlexStoxFields.AuftragErledigtPositionsId.Equal(0)));
}
Frans Bouma | Lead developer LLBLGen Pro