Skip to content
Adam Schroder edited this page Feb 2, 2015 · 11 revisions

Query<T>

Find all the users with a UserId greater than 50, order it by Name and only return 20 records offset by 40 (eg. page 3)

var users = db.Query<User>()
   .Where(x => x.UserId > 50)
   .OrderBy(x => x.Name)
   .Limit(20, 40)
   .ToList();

Note: The query will only be run when ToList(), ToEnumerable(), or any of the scalar methods that return 1 value are called (eg. Single, Count etc.)

UpdateMany<T>

Update all of type T using a Where if necessary

var list = new[] {1, 2, 3, 4};

// Update only the Name field using the template User passed 
// into Execute where the UserId in (1,2,3,4)
// If you turn ExecuteDefaults on it won't 
// set default properties (eg. null, or 0 for int)
db.UpdateMany<User>()
    .Where( x => x.UserId.In(list))
    //.ExcludeDefaults()
    .OnlyFields(x => x.Name)
    .Execute(new User() {Name = "test"});

Note: The query will only be run when Execute is called.

DeleteMany<T>

Delete all of type T using a Where if necessary

var list = new[] {1, 2, 3, 4};

db.DeleteMany<User>()
    .Where(x => list.Contains(x.UserId))
    .Execute();

Note: The query will only be run when Execute is called.