UpdateEntitiesDirectly

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 18-Mar-2008 10:44:22   

Hello

I cannot figure out the correct way to construct the IPredicate to update my table. Below is the SQL statement which I will need to fire.

UPDATE tblLookupValues SET tblLookupValues.intOrder = tblLookupValues.intOrder - 1 WHERE tblLookupValues.ipkLookupValuesID = @XYZ

Could someone please point me in the right direction.

Regards, Simon

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 18-Mar-2008 10:53:15   

Should look like the following:

// C# Adapter example:

LookupValuesEntity lookUp = new LookupValuesEntity();

lookUp.Fields[(int)LookupValuesFieldIndex.intOrder].ExpressionToApply = 
    (LookupValuesFields.intOrder - 1);

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.UpdateEntitiesDirectly(lookUp, new RelationPredicateBucket(LookupValuesFields.ipkLookupValuesID == "XYZ"));
luciusism
User
Posts: 119
Joined: 02-Jun-2007
# Posted on: 19-Mar-2008 01:03:42   

I'm curious, what is the benefit of using UpdateEntitiesDirectly is such a situation, other than brevity of code?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Mar-2008 07:06:39   

luciusism wrote:

I'm curious, what is the benefit of using UpdateEntitiesDirectly is such a situation, other than brevity of code?

Are you talking about using UpdateEntitiesDirectly or about using Native language filter construction?

David Elizondo | LLBLGen Support Team
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 20-Mar-2008 07:21:07   

daelmo wrote:

luciusism wrote:

I'm curious, what is the benefit of using UpdateEntitiesDirectly is such a situation, other than brevity of code?

Are you talking about using UpdateEntitiesDirectly or about using Native language filter construction?

I need to update other records in the table based on a where clause so I want to use UpdateEntitiesDirectly. What Native language filter construction is there?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Mar-2008 07:47:24   

I was answering the question of luciusism. The Native language filter construction is something like:

LookupValuesFields.ipkLookupValuesID == "XYZ"

@smurrell: I think the example given by Walaa is what you were looking for.

David Elizondo | LLBLGen Support Team
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 28-Apr-2009 09:09:31   

Hello Walaa

Using this code:

                // Initialize Class
                tempEntity = LookupValues_ConvertFrom(LookupValues_GetValues(Id));
                // Assign Value
                tempEntity.Fields[(int)LookupValuesFieldIndex.Order].ExpressionToApply = (LookupValuesFields.Order - 1);
                // Update Entities
                adapter.UpdateEntitiesDirectly(tempEntity, 
                    new RelationPredicateBucket((LookupValuesFields.LookupTypeId == tempEntity.LookupTypeId) &
                        (LookupValuesFields.Order > tempEntity.Order)));

I am getting the following SQL update which is updating all the field values. How do I just update the Order field?

UPDATE [tblLookupValues] SET [ifkLookupTypeID]=@LookupTypeId,[intOrder]=[tblLookupValues].[intOrder] - @LLBLEP1, [Value]=@Value WHERE ( ( ( [tblLookupValues].[ifkLookupTypeID] = @LookupTypeId2 AND [tblLookupValues].[intOrder] > @Order3)))

Regards, Simon

Walaa wrote:

Should look like the following:

// C# Adapter example:

LookupValuesEntity lookUp = new LookupValuesEntity();

lookUp.Fields[(int)LookupValuesFieldIndex.intOrder].ExpressionToApply = 
    (LookupValuesFields.intOrder - 1);

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.UpdateEntitiesDirectly(lookUp, new RelationPredicateBucket(LookupValuesFields.ipkLookupValuesID == "XYZ"));
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 28-Apr-2009 09:44:04   

UPDATE [tblLookupValues] SET [ifkLookupTypeID]=@LookupTypeId,[intOrder]=[tblLookupValues].[intOrder] - @LLBLEP1, [Value]=@Value

LLBLGenPro detetcts that the LookUpTypeID and Value fields have been set/changed in the entity passed to the UpdateEntitiesDirectly call.

                // Initialize Class
                tempEntity = LookupValues_ConvertFrom(LookupValues_GetValues(Id));
                // Assign Value

So most probably the above piece of code does set these values. As you can see that in my previous code I simple initialized an empty entity.

Walaa wrote:

LookupValuesEntity lookUp = new LookupValuesEntity();

If for some reason it's too much trouble to change your code, then all you have to do is to set the IsChanged property to false for these couple of fields. e.g.

tempEntity.Fields["Value"].IsChanged = false;