Update records with an expression over the field of the table

Posts   
 
    
Posts: 87
Joined: 17-May-2011
# Posted on: 21-Nov-2012 08:15:47   

Hi there,

I want to update the records of a table shown as below:

Update Student set Marks=Marks+10

Or like

Update Student set rate= Total/SubjectCount

Please tell me how do I do that in self service?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Nov-2012 20:29:03   

From the docs:

Expressions in entity updates Updating entities directly in the database is one of the features LLBLGen Pro offers you. You can easily update sets of entities in one query without the necessity of fetching the entities first. With an Expression applied to a field, the update queries can be even more powerful. Say you are in a generous mood and you want to update the salary of all employees with 10%? With an expression this is done in a single query. You can of course add filters to limit the scope of the update if you want. The following example illustrates the 10% salary increase. It uses the technique discussed in the entity collection section of SelfServicing, or as option 3 in modifying an entity using Adapter)

// SelfServicing // C# EmployeeEntity employee = new EmployeeEntity(); employee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)); EmployeeCollection employees = new EmployeeCollection(); // no filter is specified, everybody gets 10% extra, but you could of course // specify a filter to limit the scope of the update. employees.UpdateMulti(employee, null);

// Adapter // C# EmployeeEntity employee = new EmployeeEntity(); employee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)); DataAccessAdapter adapter = new DataAccessAdapter(); // no filter is specified, everybody gets 10% extra, but you could of course // specify a filter to limit the scope of the update. adapter.UpdateEntitiesDirectly(employee, null);