OrmLiteWriteExpressionsApiAsync
Assembly: ServiceStack.OrmLite.dll
View Source
public static class OrmLiteWriteExpressionsApiAsync : object
Methods
UpdateOnlyFieldsAsync<T>(IDbConnection, T, SqlExpression<T>, Action<IDbCommand>, CancellationToken)
Use an SqlExpression to select which fields to update and construct the where expression, E.g:
var q = db.From>Person<()); db.UpdateOnlyFieldsAsync(new Person { FirstName = "JJ" }, q.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi")); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
What's not in the update expression doesn't get updated. No where expression updates all rows. E.g:
db.UpdateOnlyFieldsAsync(new Person { FirstName = "JJ", LastName = "Hendo" }, ev.Update(p => p.FirstName)); UPDATE "Person" SET "FirstName" = 'JJ'
View Source
public static Task<int> UpdateOnlyFieldsAsync<T>(this IDbConnection dbConn, T model, SqlExpression<T> onlyFields, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | model |
ServiceStack.OrmLite.SqlExpression<T> | onlyFields |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyFieldsAsync<T>(IDbConnection, T, String[], Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
db.UpdateOnlyAsync(new Person { FirstName = "JJ" }, new[]{ "FirstName" }, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateOnlyFieldsAsync<T>(this IDbConnection dbConn, T obj, string[] onlyFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
System.String[] | onlyFields |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyFieldsAsync<T>(IDbConnection, T, Expression<Func<T, Object>>, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
db.UpdateOnlyAsync(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
db.UpdateOnlyAsync(new Person { FirstName = "JJ" }, p => p.FirstName); UPDATE "Person" SET "FirstName" = 'JJ'
View Source
public static Task<int> UpdateOnlyFieldsAsync<T>(this IDbConnection dbConn, T obj, Expression<Func<T, object>> onlyFields = null, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
Expression<Func<<T>,System.Object>> | onlyFields |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Expression<Func<T>>, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
db.UpdateOnlyAsync(() => new Person { FirstName = "JJ" }, where: p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
db.UpdateOnlyAsync(() => new Person { FirstName = "JJ" }); UPDATE "Person" SET "FirstName" = 'JJ'
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | updateFields |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Expression<Func<T>>, SqlExpression<T>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
db.UpdateOnlyAsync(() => new Person { FirstName = "JJ" }, db.From<Person>().Where(p => p.LastName == "Hendrix")); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, SqlExpression<T> q, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | updateFields |
ServiceStack.OrmLite.SqlExpression<T> | q |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Expression<Func<T>>, String, IEnumerable<IDbDataParameter>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
var q = db.From>Person<().Where(p => p.LastName == "Hendrix"); db.UpdateOnlyAsync(() => new Person { FirstName = "JJ" }, q.WhereExpression, q.Params); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, string whereExpression, IEnumerable<IDbDataParameter> sqlParams, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | updateFields |
System.String | whereExpression |
IEnumerable<IDbDataParameter> | sqlParams |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Dictionary<String, Object>, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Updates all values from Object Dictionary matching the where condition. E.g
db.UpdateOnlyAsync<Person>(new Dictionary<string,object< { {"FirstName", "JJ"} }, where:p => p.FirstName == "Jimi"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | updateFields |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Dictionary<String, Object>, Action<IDbCommand>, CancellationToken)
Updates all values from Object Dictionary, Requires Id which is used as a Primary Key Filter. E.g
db.UpdateOnlyAsync<Person>(new Dictionary<string,object< { {"Id", 1}, {"FirstName", "JJ"} }); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("Id" = 1)
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | updateFields |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateOnlyAsync<T>(IDbConnection, Dictionary<String, Object>, String, Object[], Action<IDbCommand>, CancellationToken)
Updates all values from Object Dictionary matching the where condition. E.g
db.UpdateOnlyAsync<Person>(new Dictionary<string,object< { {"FirstName", "JJ"} }, "FirstName == {0}", new[]{ "Jimi" }); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
View Source
public static Task<int> UpdateOnlyAsync<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, string whereExpression, object[] whereParams, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | updateFields |
System.String | whereExpression |
System.Object[] | whereParams |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateAddAsync<T>(IDbConnection, Expression<Func<T>>, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g: Numeric fields generates an increment sql which is useful to increment counters, etc... avoiding concurrency conflicts
db.UpdateAddAsync(() => new Person { Age = 5 }, where: p => p.LastName == "Hendrix"); UPDATE "Person" SET "Age" = "Age" + 5 WHERE ("LastName" = 'Hendrix')
db.UpdateAddAsync(() => new Person { Age = 5 }); UPDATE "Person" SET "Age" = "Age" + 5
View Source
public static Task<int> UpdateAddAsync<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | updateFields |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateAddAsync<T>(IDbConnection, Expression<Func<T>>, SqlExpression<T>, Action<IDbCommand>, CancellationToken)
Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g: Numeric fields generates an increment sql which is useful to increment counters, etc... avoiding concurrency conflicts
db.UpdateAddAsync(() => new Person { Age = 5 }, db.From<Person>().Where(p => p.LastName == "Hendrix")); UPDATE "Person" SET "Age" = "Age" + 5 WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateAddAsync<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, SqlExpression<T> q, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | updateFields |
ServiceStack.OrmLite.SqlExpression<T> | q |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateNonDefaultsAsync<T>(IDbConnection, T, Expression<Func<T, Boolean>>, CancellationToken)
Updates all non-default values set on item matching the where condition (if any). E.g
db.UpdateNonDefaultsAsync(new Person { FirstName = "JJ" }, p => p.FirstName == "Jimi"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
View Source
public static Task<int> UpdateNonDefaultsAsync<T>(this IDbConnection dbConn, T item, Expression<Func<T, bool>> obj, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | item |
Expression<Func<<T>,System.Boolean>> | obj |
CancellationToken | token |
Type Parameters
T
UpdateAsync<T>(IDbConnection, T, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Updates all values set on item matching the where condition (if any). E.g
db.UpdateAsync(new Person { Id = 1, FirstName = "JJ" }, p => p.LastName == "Hendrix"); UPDATE "Person" SET "Id" = 1,"FirstName" = 'JJ',"LastName" = NULL,"Age" = 0 WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateAsync<T>(this IDbConnection dbConn, T item, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | item |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
UpdateAsync<T>(IDbConnection, Object, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Updates all matching fields populated on anonymousType that matches where condition (if any). E.g:
db.UpdateAsync<Person>(new { FirstName = "JJ" }, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
View Source
public static Task<int> UpdateAsync<T>(this IDbConnection dbConn, object updateOnly, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.Object | updateOnly |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
InsertOnlyAsync<T>(IDbConnection, T, Expression<Func<T, Object>>, CancellationToken)
Using an SqlExpression to only Insert the fields specified, e.g:
db.InsertOnlyAsync(new Person { FirstName = "Amy" }, p => p.FirstName)); INSERT INTO "Person" ("FirstName") VALUES ('Amy');
db.InsertOnlyAsync(new Person { Id =1 , FirstName="Amy" }, p => new { p.Id, p.FirstName })); INSERT INTO "Person" ("Id", "FirstName") VALUES (1, 'Amy');
View Source
public static Task InsertOnlyAsync<T>(this IDbConnection dbConn, T obj, Expression<Func<T, object>> onlyFields, CancellationToken token = null)
Returns
Task
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
Expression<Func<<T>,System.Object>> | onlyFields |
CancellationToken | token |
Type Parameters
T
InsertOnlyAsync<T>(IDbConnection, T, String[], CancellationToken)
Using an SqlExpression to only Insert the fields specified, e.g:
db.InsertOnlyAsync(new Person { FirstName = "Amy" }, new[]{ "FirstName" })); INSERT INTO "Person" ("FirstName") VALUES ('Amy');
View Source
public static Task InsertOnlyAsync<T>(this IDbConnection dbConn, T obj, string[] onlyFields, CancellationToken token = null)
Returns
Task
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
System.String[] | onlyFields |
CancellationToken | token |
Type Parameters
T
InsertOnlyAsync<T>(IDbConnection, Expression<Func<T>>, CancellationToken)
Using an SqlExpression to only Insert the fields specified, e.g:
db.InsertOnlyAsync(() => new Person { FirstName = "Amy" })); INSERT INTO "Person" ("FirstName") VALUES (@FirstName);
View Source
public static Task<int> InsertOnlyAsync<T>(this IDbConnection dbConn, Expression<Func<T>> insertFields, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>>> | insertFields |
CancellationToken | token |
Type Parameters
T
DeleteAsync<T>(IDbConnection, Expression<Func<T, Boolean>>, Action<IDbCommand>, CancellationToken)
Delete the rows that matches the where expression, e.g:
db.DeleteAsync<Person>(p => p.Age == 27); DELETE FROM "Person" WHERE ("Age" = 27)
View Source
public static Task<int> DeleteAsync<T>(this IDbConnection dbConn, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Expression<Func<<T>,System.Boolean>> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
DeleteAsync<T>(IDbConnection, SqlExpression<T>, Action<IDbCommand>, CancellationToken)
Delete the rows that matches the where expression, e.g:
var q = db.From>Person<()); db.DeleteAsync<Person>(q.Where(p => p.Age == 27)); DELETE FROM "Person" WHERE ("Age" = 27)
View Source
public static Task<int> DeleteAsync<T>(this IDbConnection dbConn, SqlExpression<T> where, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
ServiceStack.OrmLite.SqlExpression<T> | where |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T
DeleteWhereAsync<T>(IDbConnection, String, Object[], Action<IDbCommand>, CancellationToken)
Delete the rows that matches the where filter, e.g:
db.DeleteWhereAsync<Person>("Age = {0}", new object[] { 27 }); DELETE FROM "Person" WHERE ("Age" = 27)
View Source
public static Task<int> DeleteWhereAsync<T>(this IDbConnection dbConn, string whereFilter, object[] whereParams, Action<IDbCommand> commandFilter = null, CancellationToken token = null)
Returns
Task<System.Int32>
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.String | whereFilter |
System.Object[] | whereParams |
Action<IDbCommand> | commandFilter |
CancellationToken | token |
Type Parameters
T