IExpression

Posts   
 
    
Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 06-Apr-2005 00:21:11   

Hi,

I need to update a field using an expression.

I need to assign the following IExpression to a field's ExpressionToApply property: (field * value) + value

But I can not find the way to do that. I could create the first exp1 = (field * value); but I could not create the final (exp1 + value) because there are not overload of the new method that support that kind of parameters. May be I can assign exp1 the other field's expressionToApply property; but I am not sure if that will then update the field with exp1.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Apr-2005 10:03:16   

One workaround is that you apply the field * value to a field then pass that in as the field for the actual expression with + value, and apply that expression to the field you want to update using that expression.

During the development it occured that the value operator expression variant was impossible to produce parameters for, as the type of the expression outcome was unknown, so that constructor wasn't added. Later on, a way was found to do this, though the constructor was never added.

I'll add the constructor to the 1.0.2004.2 Expression class as it's clearly an oversight.

Frans Bouma | Lead developer LLBLGen Pro
Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 06-Apr-2005 13:36:41   

Otis wrote:

One workaround is that you apply the field * value to a field then pass that in as the field for the actual expression with + value, and apply that expression to the field you want to update using that expression.

During the development it occured that the value operator expression variant was impossible to produce parameters for, as the type of the expression outcome was unknown, so that constructor wasn't added. Later on, a way was found to do this, though the constructor was never added.

I'll add the constructor to the 1.0.2004.2 Expression class as it's clearly an oversight.

The point here is the following: if I apply the expression field1 * value to a field2. Then I construct an expression using field2, may I set the field2's ExpressionToApply to nothing (null) to avoid updating field2?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Apr-2005 13:57:38   

Rogelio wrote:

Otis wrote:

One workaround is that you apply the field * value to a field then pass that in as the field for the actual expression with + value, and apply that expression to the field you want to update using that expression.

During the development it occured that the value operator expression variant was impossible to produce parameters for, as the type of the expression outcome was unknown, so that constructor wasn't added. Later on, a way was found to do this, though the constructor was never added.

I'll add the constructor to the 1.0.2004.2 Expression class as it's clearly an oversight.

The point here is the following: if I apply the expression field1 * value to a field2. Then I construct an expression using field2, may I set the field2's ExpressionToApply to nothing (null) to avoid updating field2?

In the Fields object used in the query, you set a field's ExpressionToApply to a given expression. THAT field is updated with the expression set on that field: field = Expression. Any fields used in the expression aren't set to a value, they participate in the Expression.

It depends on what kind of action you want to perform (in code): update entities directly, load an entity, set field's expression, save again, etc. Could you give me a sample code snippet so I can see what you want to achieve in context?

Frans Bouma | Lead developer LLBLGen Pro
Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 06-Apr-2005 15:12:17   

Otis wrote:

Rogelio wrote:

Otis wrote:

One workaround is that you apply the field * value to a field then pass that in as the field for the actual expression with + value, and apply that expression to the field you want to update using that expression.

During the development it occured that the value operator expression variant was impossible to produce parameters for, as the type of the expression outcome was unknown, so that constructor wasn't added. Later on, a way was found to do this, though the constructor was never added.

I'll add the constructor to the 1.0.2004.2 Expression class as it's clearly an oversight.

The point here is the following: if I apply the expression field1 * value to a field2. Then I construct an expression using field2, may I set the field2's ExpressionToApply to nothing (null) to avoid updating field2?

In the Fields object used in the query, you set a field's ExpressionToApply to a given expression. THAT field is updated with the expression set on that field: field = Expression. Any fields used in the expression aren't set to a value, they participate in the Expression.

It depends on what kind of action you want to perform (in code): update entities directly, load an entity, set field's expression, save again, etc. Could you give me a sample code snippet so I can see what you want to achieve in context?

For example: I have an Entity (MyEntity) with two fields (field1 and field2) and a primary key (fieldPK). I need to read the entity, then I need to update field2 with an expression (field2 = (field2 * value) + value).

entity = New MyEntity(primaryKeyValue) adapter.FetchEntity(entity) ... use the value of field1 and field2 for some calculations.... ... entity.field1.expressionToApply = expression(field2 * value) entity.field2.expressionToApply = expression(field1 + value) adapter.SaveEntity(entity)

What will happen with field1 during the update? Will it be updated because it has an expression applied?

I would like to know when does LLBLGen Pro use the expression that is inside field1: - entity.field2.expressionToApply = expression(field1 + value), after this statement, may I set entity.field1.expressionToApply = nothing, then adapter.SaveEntity(entity). Does field2 will be updated correctly?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Apr-2005 16:51:50   

Rogelio wrote:

Otis wrote:

Rogelio wrote:

Otis wrote:

One workaround is that you apply the field * value to a field then pass that in as the field for the actual expression with + value, and apply that expression to the field you want to update using that expression.

During the development it occured that the value operator expression variant was impossible to produce parameters for, as the type of the expression outcome was unknown, so that constructor wasn't added. Later on, a way was found to do this, though the constructor was never added.

I'll add the constructor to the 1.0.2004.2 Expression class as it's clearly an oversight.

The point here is the following: if I apply the expression field1 * value to a field2. Then I construct an expression using field2, may I set the field2's ExpressionToApply to nothing (null) to avoid updating field2?

In the Fields object used in the query, you set a field's ExpressionToApply to a given expression. THAT field is updated with the expression set on that field: field = Expression. Any fields used in the expression aren't set to a value, they participate in the Expression.

It depends on what kind of action you want to perform (in code): update entities directly, load an entity, set field's expression, save again, etc. Could you give me a sample code snippet so I can see what you want to achieve in context?

For example: I have an Entity (MyEntity) with two fields (field1 and field2) and a primary key (fieldPK). I need to read the entity, then I need to update field2 with an expression (field2 = (field2 * value) + value).

entity = New MyEntity(primaryKeyValue) adapter.FetchEntity(entity) ... use the value of field1 and field2 for some calculations.... ... entity.field1.expressionToApply = expression(field2 * value) entity.field2.expressionToApply = expression(field1 + value) adapter.SaveEntity(entity)

What will happen with field1 during the update? Will it be updated because it has an expression applied?

I would like to know when does LLBLGen Pro use the expression that is inside field1: - entity.field2.expressionToApply = expression(field1 + value), after this statement, may I set entity.field1.expressionToApply = nothing, then adapter.SaveEntity(entity). Does field2 will be updated correctly?

Field objects will be transformed into field names to be part of the query. If a field has an expression applied to it, the expression will be used in an UPDATE query as the new value for the field the expression is applied to.

so: entity.field1.expressionToApply = expression(field2 * value) will result in: UPDATE .. SET field1 = (field2 * value)

however, because the field2 instance also has an expression applied to it, as is done in: entity.field2.expressionToApply = expression(field1 + value)

it will result in an infinite loop IF the field2 instance in this line: entity.field1.expressionToApply = expression(field2 * value) is the same as the field2 instance in this line: entity.field2.expressionToApply = expression(field1 + value)

To avoid that, create new Field1 and Field2 instances for usage in the expressions. That way you'll get the expression you want.

I've added Expression op Value and Value op Expression to 1.0.2004.2 and will be avialble in the next beta build.

Frans Bouma | Lead developer LLBLGen Pro