RelationPredicateBucket not working for UpdateEntitiesDirectly

Posts   
 
    
ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 07-Jan-2013 22:49:31   

I'm using runtime version 3.5.12.1101, 2-class Adapter, SQL Server.

I have an entity B that is in an inheritance hierarchy (target per entity). It inherits from entity A. I am trying to update entity B using UpdateEntitiesDirectly, passing a RelationPredicateBucket specifying the key fields of the entity so the update is restricted to a single record.

If, in the entity instance I pass to the method, I have only updated fields that are defined in entity B, it works correctly. However, if I also update one or more fields that are inherited from A, it does not work correctly.

Specifically, LLBLGen issues two database updates. The first statement updates the table for A, and that includes the WHERE clause generated from the RelationPredicateBucket. However, the second statement, which updates the table for B, does not include the WHERE clause, so it updates all rows in the table.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Jan-2013 05:57:17   

I reproduced it with latest LLBGen Framework, using InheritanceOne db.

RTL ORMSupportClasses: 3.5.12.1220

Code

var newValues = new ManagerEntity();
newValues.ManagesDepartmentId = 1; // at Manager target
newValues.StartDate = DateTime.Now; // at Employee target

var filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(ManagerFields.EmployeeId == 2);

using (var adapter = new DataAccessAdapter())
{
    adapter.UpdateEntitiesDirectly(newValues, filter);
}

Generated SQL

#1
UPDATE [InheritanceOne].[dbo].[Employee]
SET [StartDate] = @p1
FROM   ( [InheritanceOne].[dbo].[Employee]
         LEFT JOIN [InheritanceOne].[dbo].[Manager]
             ON [InheritanceOne].[dbo].[Employee].[EmployeeID] = [InheritanceOne].[dbo].[Manager].[ManagerID])
WHERE  ((([InheritanceOne].[dbo].[Manager].[ManagerID] = @p2))) 

#2
UPDATE [InheritanceOne].[dbo].[Manager]
SET [ManagesDepartmentID] = @p3 

We will look into this. In the meantime, as a workaround use the traditional fetch-modify-save approach.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 08-Jan-2013 09:51:11   

Hmm, this is a nasty bug! disappointed Looking into it now.

(edit) in batch updates, it simply doesn't append the filter for the second and so on queries. It does append the PK filter, so updates of subtypes work but batch updates don't. This issue has been in the code since before v2.0. Bizarre that it's not been reported (nor did we find it) till today!

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 08-Jan-2013 11:08:12   

Fixed. See attached dll.

Attachments
Filename File size Added on Approval
SD.LLBLGen.Pro.ORMSupportClasses.NET20.zip 249,701 08-Jan-2013 11:08.40 Approved
Frans Bouma | Lead developer LLBLGen Pro
ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 08-Jan-2013 16:39:05   

Thanks as always for the quick fix.