Update field using another field

Posts   
 
    
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 28-Oct-2013 19:37:51   

Hi, How can i write this using the generated code?


UPDATE GradeBook.GradeBookItem 
SET PercentValue = CASE WHEN RecordedGrade IS NULL THEN NULL else RecordedGrade / 12 END

WHERE AssignmentId=562645

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Oct-2013 06:52:43   

Hi shane. Do something like this:

var newValues = new GradeBookItemEntity();
newValues.Fields[(int)GradeBookItemFieldIndex.PercentValue].SetExpression(
    new DbFunctionCall("CASE WHEN {0} IS NULL THEN NULL ELSE {0} / 12 END",
        new object[] { GradeBookItemFields.RecordedGrade }));

var filter = new PredicateExpression(GradeBookItemFields.AssignmentId == 562645);

var rowsAffected = new GradeBookItemDAO().UpdateMulti(newValues, null, filter);

You also could use a GradeBookItemCollection istead of GradeBookItemDAO. This is explained here in the docs....

David Elizondo | LLBLGen Support Team
e106199
User
Posts: 175
Joined: 09-Sep-2006
# Posted on: 29-Oct-2013 14:46:38   

Thank you. that is what i was looking for.

-shane