Ermias Y
Ermias Y

Reputation: 263

servicestack ormlite partial update

I'm using ServiceStack Ormlite to do partial update to a database table.

I have a model:

public class Model
{
    public int Id;
    public int Property1;
    public int Property2;
    public int Property3;
}

But I only want to update fields Property1, and Property2.

Does anybody know how to do this?

Thanks.

Upvotes: 2

Views: 4942

Answers (2)

Dudeman3000
Dudeman3000

Reputation: 601

Here is what an ServiceStack OrmLite multiple field update with where clause looks like:

Db.UpdateOnly(
new Table_DTO_Object { Field_1 = Val_1, Field_2 = Val_2, Field_3 = Val_3 }, 
obj => new { obj.Field_1, obj.Field_2, obj.Field_3 }, 
obj => obj.Id == objId);

How to update multiple fields on a single table row / with a where clause is not immediately apparent from the ServiceStack documentation because they don't have an example with both 1) multiple fields and 2) where clause.

They have an example that updates multiple fields and they have an example of an update with a where clause - really all you need to do / I did is take the needed functionality from each example.

Upvotes: 3

mythz
mythz

Reputation: 143284

See ServiceStack's OrmLite documentation for Update statements - they contain many different different examples of partial updates.

Upvotes: 8

Related Questions