Table of Contents

Method SetFieldAsCase

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

SetFieldAsCase(ISelectItem, Case)

Sets a field value to a Case expression, so the value written depends on the row.

public void SetFieldAsCase(ISelectItem selectItem, Case caseItem)

Parameters

selectItem ISelectItem

The column to set.

caseItem Case

The case expression that produces the value.

Examples

Classifying every row in one UPDATE:

Case dominantSex = new Case()
    .When(new Criterion<Column>(names["male_count"], ConditionalType.GreaterThanOrEqualTo, names["female_count"]),
          new Literal<string>("Male"))
    .Else(new Literal<string>("Female"));

Update update = new Update(names);
update.SetFieldAsCase("sex", dominantSex);

manager.UpdateRecords(update);

// SQL: UPDATE names SET sex = (CASE WHEN male_count >= female_count THEN 'Male' ELSE 'Female' END)

Remarks

This is the conditional counterpart to SetFieldAsExpression(ISelectItem, Expression): every row gets the value of whichever branch matches it, evaluated by the database in a single statement rather than by reading rows into the application and writing them back one at a time.

The case expression is stored as an expression field, so HasFieldAsExpression(ISelectItem) and GetFieldAsExpression(ISelectItem) report on a field set this way.

SetFieldAsCase(string, Case)

Sets a field value to a Case expression, so the value written depends on the row.

public void SetFieldAsCase(string fieldName, Case caseItem)

Parameters

fieldName string

The name of the column to set.

caseItem Case

The case expression that produces the value.

Remarks

See SetFieldAsCase(ISelectItem, Case) for details and an example.