ExpressionToApply in select and where

Posts   
 
    
sami
User
Posts: 93
Joined: 28-Oct-2005
# Posted on: 24-Jan-2006 20:39:33   

Maybe you guys could help me out with this one. So, if I apply .ExpressionToApply to my field, like this:


entity.Fields["somefield"].ExpressionToApply = someExpression;

The expression is then applied to update statement and predicate? What if I have the same field in both update statement AND predicate?

For example, I would like to make this kind of SQL statement:


update mytable set somefield = somefield+2 where somefield> 5 

If I create code for above functionality the sql which gets executed is ;


update mytable set somefield= somefield+2 where somefield+ 2 > 5 

So, the expression (somefield + 2) is applied to both update and predicate, which is not what I want to do, Any other solutions than fetching the stuff or using stored proc?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jan-2006 06:53:02   

We will be looking at this.

In the mean time you can workaround by using something like this:

update mytable set somefield= somefield+2 where somefield+ 2 > 3

Or you may Fetch your Entities, then loop in the collection and do something like

YourEntity.YourField = YourEntity.YourField + 2

Then save the collection.

sami
User
Posts: 93
Joined: 28-Oct-2005
# Posted on: 25-Jan-2006 09:24:34   

Actually the workaround is to do;

update mytable set somefield= somefield+2 where somefield+ 2 > 7

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 25-Jan-2006 10:17:08   

sami wrote:

Maybe you guys could help me out with this one. So, if I apply .ExpressionToApply to my field, like this:


entity.Fields["somefield"].ExpressionToApply = someExpression;

The expression is then applied to update statement and predicate?

No, it's applied to the field in an UPDATE query. So if you do: myEmployee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary * 1.10f);

it will become: UPDATE employee SET salary = (salary * 1.10) WHERE <pk filter>

What if I have the same field in both update statement AND predicate? For example, I would like to make this kind of SQL statement:


update mytable set somefield = somefield+2 where somefield> 5 

If I create code for above functionality the sql which gets executed is ;


update mytable set somefield= somefield+2 where somefield+ 2 > 5 

If you re-use the field object, yes that's true.

So, the expression (somefield + 2) is applied to both update and predicate, which is not what I want to do, Any other solutions than fetching the stuff or using stored proc?

use a new field object for the predicate:

myEmployee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary * 1.10f); IPredicate filter = (EmployeeFields.Salary > 100,000);

Frans Bouma | Lead developer LLBLGen Pro