UpdateEntitiesDirectly on subtype fails for batch updates

Posts   
 
    
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 19-Mar-2014 14:46:11   

Using 4.1 March 12th build.

SubDetailEntity is subtype of DetailEntity.

Trying to do a batch update on the subtype, this code

var filter = new RelationPredicateBucket(SubDetailFields.OrderId == 12345);
Adapter.UpdateEntitiesDirectly(new SubDetailEntity{ Field = false }, filter);

produces this SQL

UPDATE [SubDetail]
SET [Field] = @p1
WHERE  ((([Detail].[OrderId] = @p2)))

which fails with error

The multi-part identifier "Detail.OrderId" could not be bound.

because there is no JOIN with the supertype.

But when I filter on the PK of the subtype (and supertype)

var filter = new RelationPredicateBucket(SubDetailFields.Id == 54321);
Adapter.UpdateEntitiesDirectly(new SubDetailEntity{ Field = false }, filter);

then this SQL is generated

UPDATE [SubDetail]
SET [Field] = @p1
FROM   ( [Detail]
         LEFT JOIN [SubDetail]
             ON [Detail].[Id] = [SubDetail].[Id])
WHERE  ((([SubDetail].[Id] = @p2))) 

in which the FROM with JOIN is not really necessary in my opinion.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Mar-2014 04:22:03   

Is the OrderId field defined in the DetailEntity?

twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 20-Mar-2014 09:39:18   

Walaa wrote:

Is the OrderId field defined in the DetailEntity?

Yes. OrderId is a column in DetailEntity. Field in SubDetailEntity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Mar-2014 10:12:26   

Odd. We'll look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Mar-2014 11:44:32   

Hmm, we have a couple of tests for this method, and I see we missed the scenario you're using. There are a couple of scenarios: update subtype or supertype field and no filter, update supertype field and subtype field, update subtype field and subtype filter, update subtype field and supertype filter. Although the system should automatically add the right joins based on the elements used in the statement, the tests we have missed your situation, namely update subtype field and supertype filter. We'll add that now and see whether it reproduces your problem.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 21-Mar-2014 11:52:26   

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Mar-2014 11:54:43   

Reproduced...

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Mar-2014 12:14:31   

Code which should fix it is there but works on the wrong variable flushed How stupid. Will fix it and attach a new build for you.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 21-Mar-2014 12:20:50   

Otis wrote:

Code which should fix it is there but works on the wrong variable flushed How stupid. Will fix it and attach a new build for you.

Great, but don't forget your lunch smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Mar-2014 12:24:11   

See attached fix simple_smile I attached both the .net 3.5 and .net 4.5 build

twaindev wrote:

Otis wrote:

Code which should fix it is there but works on the wrong variable flushed How stupid. Will fix it and attach a new build for you.

Great, but don't forget your lunch smile

Good point simple_smile Will grab one now simple_smile Let me know if the fix fails in your situation (all tests pass here)

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 21-Mar-2014 14:43:00   

Otis wrote:

Let me know if the fix fails in your situation (all tests pass here)

The generated SQL now looks like this

UPDATE [SubDetaiL]
SET [Field] = @p1
FROM   ( [Detail]
         INNER JOIN [SubDetaiL]
             ON [Detail].[Id] = [SubDetaiL].[Id])
WHERE  ((([Detail].[OrderId] = @p2))) 

so it is ok now simple_smile

Thanks