Skip to main content

OrmLiteWriteExpressionsApi

Assembly: ServiceStack.OrmLite.dll
View Source
Declaration
public static class OrmLiteWriteExpressionsApi : object

Methods

UpdateOnlyFields<T>(IDbConnection, T, SqlExpression<T>, Action<IDbCommand>)

Use an SqlExpression to select which fields to update and construct the where expression, E.g:

var q = db.From>Person<()); db.UpdateOnlyFields(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.UpdateOnlyFields(new Person { FirstName = "JJ", LastName = "Hendo" }, ev.Update(p => p.FirstName)); UPDATE "Person" SET "FirstName" = 'JJ'

View Source
Declaration
public static int UpdateOnlyFields<T>(this IDbConnection dbConn, T model, SqlExpression<T> onlyFields, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
<T>model
ServiceStack.OrmLite.SqlExpression<T>onlyFields
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnlyFields<T>(IDbConnection, T, String[], Expression<Func<T, Boolean>>, Action<IDbCommand>)

Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:

db.UpdateOnly(new Person { FirstName = "JJ" }, new[]{ "FirstName" }, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

View Source
Declaration
public static int UpdateOnlyFields<T>(this IDbConnection dbConn, T obj, string[] onlyFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
<T>obj
System.String[]onlyFields
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnlyFields<T>(IDbConnection, T, Expression<Func<T, Object>>, Expression<Func<T, Boolean>>, Action<IDbCommand>)

Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:

db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName); UPDATE "Person" SET "FirstName" = 'JJ'

db.UpdateOnly(new Person { FirstName = "JJ", Age = 27 }, p => new { p.FirstName, p.Age ); UPDATE "Person" SET "FirstName" = 'JJ', "Age" = 27

View Source
Declaration
public static int UpdateOnlyFields<T>(this IDbConnection dbConn, T obj, Expression<Func<T, object>> onlyFields = null, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
<T>obj
Expression<Func<<T>,System.Object>>onlyFields
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Expression<Func<T>>, Expression<Func<T, Boolean>>, Action<IDbCommand>)

Update only fields in the specified expression that matches the where condition (if any), E.g:

db.UpdateOnly(() => new Person { FirstName = "JJ" }, where: p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

db.UpdateOnly(() => new Person { FirstName = "JJ" }); UPDATE "Person" SET "FirstName" = 'JJ'

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>updateFields
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Expression<Func<T>>, SqlExpression<T>, Action<IDbCommand>)

Update only fields in the specified expression that matches the where condition (if any), E.g:

db.UpdateOnly(() => new Person { FirstName = "JJ" }, db.From>Person<().Where(p => p.LastName == "Hendrix")); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, SqlExpression<T> q, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>updateFields
ServiceStack.OrmLite.SqlExpression<T>q
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Expression<Func<T>>, String, IEnumerable<IDbDataParameter>, Action<IDbCommand>)

Update only fields in the specified expression that matches the where condition (if any), E.g:

var q = db.From>Person<().Where(p => p.LastName == "Hendrix"); db.UpdateOnly(() => new Person { FirstName = "JJ" }, q.WhereExpression, q.Params); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, string whereExpression, IEnumerable<IDbDataParameter> sqlParams, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>updateFields
System.StringwhereExpression
IEnumerable<IDbDataParameter>sqlParams
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Dictionary<String, Object>, Expression<Func<T, Boolean>>)

Updates all values from Object Dictionary matching the where condition. E.g

db.UpdateOnly<Person>(new Dictionary<string,object< { {"FirstName", "JJ"} }, where:p => p.FirstName == "Jimi"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Expression<Func<T, bool>> obj)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Dictionary<System.String,System.Object>updateFields
Expression<Func<<T>,System.Boolean>>obj
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Dictionary<String, Object>, Action<IDbCommand>)

Updates all values from Object Dictionary, Requires Id which is used as a Primary Key Filter. E.g

db.UpdateOnly<Person>(new Dictionary<string,object< { {"Id", 1}, {"FirstName", "JJ"} }); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("Id" = 1)

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Dictionary<System.String,System.Object>updateFields
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateOnly<T>(IDbConnection, Dictionary<String, Object>, String, Object[], Action<IDbCommand>)

Updates all values from Object Dictionary matching the where condition. E.g

db.UpdateOnly<Person>(new Dictionary<string,object< { {"FirstName", "JJ"} }, "FirstName == {0}", new[] { "Jimi" }); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')

View Source
Declaration
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, string whereExpression, object[] whereParams, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Dictionary<System.String,System.Object>updateFields
System.StringwhereExpression
System.Object[]whereParams
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateAdd<T>(IDbConnection, Expression<Func<T>>, Expression<Func<T, Boolean>>, Action<IDbCommand>)

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.UpdateAdd(() => new Person { Age = 5 }, where: p => p.LastName == "Hendrix"); UPDATE "Person" SET "Age" = "Age" + 5 WHERE ("LastName" = 'Hendrix')

db.UpdateAdd(() => new Person { Age = 5 }); UPDATE "Person" SET "Age" = "Age" + 5

View Source
Declaration
public static int UpdateAdd<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>updateFields
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateAdd<T>(IDbConnection, Expression<Func<T>>, SqlExpression<T>, Action<IDbCommand>)

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.UpdateAdd(() => new Person { Age = 5 }, db.From<Person>().Where(p => p.LastName == "Hendrix")); UPDATE "Person" SET "Age" = "Age" + 5 WHERE ("LastName" = 'Hendrix')

View Source
Declaration
public static int UpdateAdd<T>(this IDbConnection dbConn, Expression<Func<T>> updateFields, SqlExpression<T> q, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>updateFields
ServiceStack.OrmLite.SqlExpression<T>q
Action<IDbCommand>commandFilter
Type Parameters
  • T

UpdateNonDefaults<T>(IDbConnection, T, Expression<Func<T, Boolean>>)

Updates all non-default values set on item matching the where condition (if any). E.g

db.UpdateNonDefaults(new Person { FirstName = "JJ" }, p => p.FirstName == "Jimi"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')

View Source
Declaration
public static int UpdateNonDefaults<T>(this IDbConnection dbConn, T item, Expression<Func<T, bool>> obj)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
<T>item
Expression<Func<<T>,System.Boolean>>obj
Type Parameters
  • T

Update<T>(IDbConnection, T, Expression<Func<T, Boolean>>, Action<IDbCommand>)

Updates all values set on item matching the where condition (if any). E.g

db.Update(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
Declaration
public static int Update<T>(this IDbConnection dbConn, T item, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
<T>item
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

Update<T>(IDbConnection, Object, Expression<Func<T, Boolean>>, Action<IDbCommand>)

Updates all matching fields populated on anonymousType that matches where condition (if any). E.g:

db.Update<Person>(new { FirstName = "JJ" }, p => p.LastName == "Hendrix"); UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

View Source
Declaration
public static int Update<T>(this IDbConnection dbConn, object updateOnly, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
System.ObjectupdateOnly
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

InsertOnly<T>(IDbConnection, T, Expression<Func<T, Object>>, Boolean)

Using an SqlExpression to only Insert the fields specified, e.g:

db.InsertOnly(new Person { FirstName = "Amy" }, p => p.FirstName)); INSERT INTO "Person" ("FirstName") VALUES ('Amy');

db.InsertOnly(new Person { Id =1 , FirstName="Amy" }, p => new { p.Id, p.FirstName })); INSERT INTO "Person" ("Id", "FirstName") VALUES (1, 'Amy');

View Source
Declaration
public static long InsertOnly<T>(this IDbConnection dbConn, T obj, Expression<Func<T, object>> onlyFields, bool selectIdentity = false)
Returns

System.Int64

Parameters
TypeName
IDbConnectiondbConn
<T>obj
Expression<Func<<T>,System.Object>>onlyFields
System.BooleanselectIdentity
Type Parameters
  • T

InsertOnly<T>(IDbConnection, T, String[], Boolean)

Using an SqlExpression to only Insert the fields specified, e.g:

db.InsertOnly(new Person { FirstName = "Amy" }, new[]{ "FirstName" })); INSERT INTO "Person" ("FirstName") VALUES ('Amy');

View Source
Declaration
public static long InsertOnly<T>(this IDbConnection dbConn, T obj, string[] onlyFields, bool selectIdentity = false)
Returns

System.Int64

Parameters
TypeName
IDbConnectiondbConn
<T>obj
System.String[]onlyFields
System.BooleanselectIdentity
Type Parameters
  • T

InsertOnly<T>(IDbConnection, Expression<Func<T>>, Boolean)

Using an SqlExpression to only Insert the fields specified, e.g:

db.InsertOnly(() => new Person { FirstName = "Amy" })); INSERT INTO "Person" ("FirstName") VALUES (@FirstName);

View Source
Declaration
public static long InsertOnly<T>(this IDbConnection dbConn, Expression<Func<T>> insertFields, bool selectIdentity = false)
Returns

System.Int64

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>>>insertFields
System.BooleanselectIdentity
Type Parameters
  • T

Delete<T>(IDbConnection, Expression<Func<T, Boolean>>, Action<IDbCommand>)

Delete the rows that matches the where expression, e.g:

db.Delete<Person>(p => p.Age == 27); DELETE FROM "Person" WHERE ("Age" = 27)

View Source
Declaration
public static int Delete<T>(this IDbConnection dbConn, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>,System.Boolean>>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

Delete<T>(IDbConnection, SqlExpression<T>, Action<IDbCommand>)

Delete the rows that matches the where expression, e.g:

var q = db.From<Person>()); db.Delete<Person>(q.Where(p => p.Age == 27)); DELETE FROM "Person" WHERE ("Age" = 27)

View Source
Declaration
public static int Delete<T>(this IDbConnection dbConn, SqlExpression<T> where, Action<IDbCommand> commandFilter = null)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.SqlExpression<T>where
Action<IDbCommand>commandFilter
Type Parameters
  • T

DeleteWhere<T>(IDbConnection, String, Object[])

Delete the rows that matches the where filter, e.g:

db.DeleteWhere<Person>("Age = {0}", new object[] { 27 }); DELETE FROM "Person" WHERE ("Age" = 27)

View Source
Declaration
public static int DeleteWhere<T>(this IDbConnection dbConn, string whereFilter, object[] whereParams)
Returns

System.Int32

Parameters
TypeName
IDbConnectiondbConn
System.StringwhereFilter
System.Object[]whereParams
Type Parameters
  • T