OrmLiteWriteApi
Assembly: ServiceStack.OrmLite.dll
View Source
public static class OrmLiteWriteApi : object
Methods
GetLastSql(IDbConnection)
Get the last SQL statement that was executed.
View Source
public static string GetLastSql(this IDbConnection dbConn)
Returns
System.String
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
GetLastSqlAndParams(IDbCommand)
View Source
public static string GetLastSqlAndParams(this IDbCommand dbCmd)
Returns
System.String
Parameters
Type | Name |
---|---|
IDbCommand | dbCmd |
ExecuteSql(IDbConnection, String)
Execute any arbitrary raw SQL.
View Source
public static int ExecuteSql(this IDbConnection dbConn, string sql)
Returns
System.Int32
: number of rows affected
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.String | sql |
ExecuteSql(IDbConnection, String, Object)
Execute any arbitrary raw SQL with db params.
View Source
public static int ExecuteSql(this IDbConnection dbConn, string sql, object dbParams)
Returns
System.Int32
: number of rows affected
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.String | sql |
System.Object | dbParams |
ExecuteSql(IDbConnection, String, Dictionary<String, Object>)
Execute any arbitrary raw SQL with db params.
View Source
public static int ExecuteSql(this IDbConnection dbConn, string sql, Dictionary<string, object> dbParams)
Returns
System.Int32
: number of rows affected
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.String | sql |
Dictionary<System.String,System.Object> | dbParams |
Insert<T>(IDbConnection, T, Boolean, Boolean)
Insert 1 POCO, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g: <p>var id = db.Insert(new Person { Id = 1, FirstName = "Jimi }, selectIdentity:true)</p>
View Source
public static long Insert<T>(this IDbConnection dbConn, T obj, bool selectIdentity = false, bool enableIdentityInsert = false)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
System.Boolean | selectIdentity |
System.Boolean | enableIdentityInsert |
Type Parameters
T
Insert<T>(IDbConnection, T, Action<IDbCommand>, Boolean)
Insert 1 POCO and modify populated IDbCommand with a commandFilter. E.g: <p>var id = db.Insert(new Person { Id = 1, FirstName = "Jimi }, dbCmd => applyFilter(dbCmd))</p>
View Source
public static long Insert<T>(this IDbConnection dbConn, T obj, Action<IDbCommand> commandFilter, bool selectIdentity = false)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
Action<IDbCommand> | commandFilter |
System.Boolean | selectIdentity |
Type Parameters
T
Insert<T>(IDbConnection, Dictionary<String, Object>, Boolean)
Insert 1 POCO, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g: <p>var id = db.Insert(new Dictionary<string,object> { ["Id"] = 1, ["FirstName"] = "Jimi }, selectIdentity:true)</p>
View Source
public static long Insert<T>(this IDbConnection dbConn, Dictionary<string, object> obj, bool selectIdentity = false)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | obj |
System.Boolean | selectIdentity |
Type Parameters
T
Insert<T>(IDbConnection, Action<IDbCommand>, Dictionary<String, Object>, Boolean)
Insert 1 POCO, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g: <p>var id = db.Insert(new Dictionary<string,object> { ["Id"] = 1, ["FirstName"] = "Jimi }, dbCmd => applyFilter(dbCmd))</p>
View Source
public static long Insert<T>(this IDbConnection dbConn, Action<IDbCommand> commandFilter, Dictionary<string, object> obj, bool selectIdentity = false)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Action<IDbCommand> | commandFilter |
Dictionary<System.String,System.Object> | obj |
System.Boolean | selectIdentity |
Type Parameters
T
InsertUsingDefaults<T>(IDbConnection, T[])
Insert 1 or more POCOs in a transaction using Table default values when defined. E.g: <p>db.InsertUsingDefaults(new Person { FirstName = "Tupac", LastName = "Shakur" },</p> <p> new Person { FirstName = "Biggie", LastName = "Smalls" })</p>
View Source
public static void InsertUsingDefaults<T>(this IDbConnection dbConn, params T[] objs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | objs |
Type Parameters
T
InsertIntoSelect<T>(IDbConnection, ISqlExpression)
Insert results from SELECT SqlExpression, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g: <p>db.InsertIntoSelect<Contact>(db.From<Person>().Select(x => new { x.Id, Surname == x.LastName }))</p>
View Source
public static long InsertIntoSelect<T>(this IDbConnection dbConn, ISqlExpression query)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
ServiceStack.OrmLite.ISqlExpression | query |
Type Parameters
T
InsertIntoSelect<T>(IDbConnection, ISqlExpression, Action<IDbCommand>)
Insert results from SELECT SqlExpression, use selectIdentity to retrieve the last insert AutoIncrement id (if any). E.g: <p>db.InsertIntoSelect<Contact>(db.From<Person>().Select(x => new { x.Id, Surname == x.LastName }))</p>
View Source
public static long InsertIntoSelect<T>(this IDbConnection dbConn, ISqlExpression query, Action<IDbCommand> commandFilter)
Returns
System.Int64
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
ServiceStack.OrmLite.ISqlExpression | query |
Action<IDbCommand> | commandFilter |
Type Parameters
T
InsertAll<T>(IDbConnection, IEnumerable<T>)
Insert a collection of POCOs in a transaction. E.g: <p>db.InsertAll(new[] { new Person { Id = 9, FirstName = "Biggie", LastName = "Smalls", Age = 24 } })</p>
View Source
public static void InsertAll<T>(this IDbConnection dbConn, IEnumerable<T> objs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable<<T>> | objs |
Type Parameters
T
InsertAll<T>(IDbConnection, IEnumerable<T>, Action<IDbCommand>)
Insert a collection of POCOs in a transaction and modify populated IDbCommand with a commandFilter. E.g: <p>db.InsertAll(new[] { new Person { Id = 9, FirstName = "Biggie", LastName = "Smalls", Age = 24 } },</p> <p> dbCmd => applyFilter(dbCmd))</p>
View Source
public static void InsertAll<T>(this IDbConnection dbConn, IEnumerable<T> objs, Action<IDbCommand> commandFilter)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable<<T>> | objs |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Insert<T>(IDbConnection, T[])
Insert 1 or more POCOs in a transaction. E.g: <p>db.Insert(new Person { Id = 1, FirstName = "Tupac", LastName = "Shakur", Age = 25 },</p> <p> new Person { Id = 2, FirstName = "Biggie", LastName = "Smalls", Age = 24 })</p>
View Source
public static void Insert<T>(this IDbConnection dbConn, params T[] objs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | objs |
Type Parameters
T
Insert<T>(IDbConnection, Action<IDbCommand>, T[])
Insert 1 or more POCOs in a transaction and modify populated IDbCommand with a commandFilter. E.g: <p>db.Insert(dbCmd => applyFilter(dbCmd),</p> <p> new Person { Id = 1, FirstName = "Tupac", LastName = "Shakur", Age = 25 },</p> <p> new Person { Id = 2, FirstName = "Biggie", LastName = "Smalls", Age = 24 })</p>
View Source
public static void Insert<T>(this IDbConnection dbConn, Action<IDbCommand> commandFilter, params T[] objs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Action<IDbCommand> | commandFilter |
<T>[] | objs |
Type Parameters
T
Update<T>(IDbConnection, T, Action<IDbCommand>)
Updates 1 POCO. All fields are updated except for the PrimaryKey which is used as the identity selector. E.g: <p>db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 })</p>
View Source
public static int Update<T>(this IDbConnection dbConn, T obj, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Update<T>(IDbConnection, Dictionary<String, Object>, Action<IDbCommand>)
Updates 1 POCO. All fields are updated except for the PrimaryKey which is used as the identity selector. E.g: <p>db.Update(new Dictionary<string,object> { ["Id"] = 1, ["FirstName"] = "Jimi" })</p>
View Source
public static int Update<T>(this IDbConnection dbConn, Dictionary<string, object> obj, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | obj |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Update<T>(IDbConnection, T[])
Updates 1 or more POCOs in a transaction. E.g: <p>db.Update(new Person { Id = 1, FirstName = "Tupac", LastName = "Shakur", Age = 25 },</p> <p>new Person { Id = 2, FirstName = "Biggie", LastName = "Smalls", Age = 24 })</p>
View Source
public static int Update<T>(this IDbConnection dbConn, params T[] objs)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | objs |
Type Parameters
T
Update<T>(IDbConnection, Action<IDbCommand>, T[])
View Source
public static int Update<T>(this IDbConnection dbConn, Action<IDbCommand> commandFilter, params T[] objs)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Action<IDbCommand> | commandFilter |
<T>[] | objs |
Type Parameters
T
UpdateAll<T>(IDbConnection, IEnumerable<T>, Action<IDbCommand>)
Updates 1 or more POCOs in a transaction. E.g: <p>db.UpdateAll(new[] { new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 } })</p>
View Source
public static int UpdateAll<T>(this IDbConnection dbConn, IEnumerable<T> objs, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable<<T>> | objs |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Delete<T>(IDbConnection, Object, Action<IDbCommand>)
Delete rows using an anonymous type filter. E.g: <p>db.Delete<Person>(new { FirstName = "Jimi", Age = 27 })</p>
View Source
public static int Delete<T>(this IDbConnection dbConn, object anonFilter, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.Object | anonFilter |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Delete<T>(IDbConnection, Dictionary<String, Object>)
Delete rows using an Object Dictionary filters. E.g: <p>db.Delete<Person>(new Dictionary<string,object> { ["FirstName"] = "Jimi", ["Age"] = 27 })</p>
View Source
public static int Delete<T>(this IDbConnection dbConn, Dictionary<string, object> filters)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Dictionary<System.String,System.Object> | filters |
Type Parameters
T
Delete<T>(IDbConnection, T, Action<IDbCommand>)
Delete 1 row using all fields in the filter. E.g: <p>db.Delete(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 })</p>
View Source
public static int Delete<T>(this IDbConnection dbConn, T allFieldsFilter, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | allFieldsFilter |
Action<IDbCommand> | commandFilter |
Type Parameters
T
Delete<T>(IDbConnection, T[])
Delete 1 or more rows in a transaction using all fields in the filter. E.g: <p>db.Delete(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 })</p>
View Source
public static int Delete<T>(this IDbConnection dbConn, params T[] allFieldsFilters)
Returns
System.Int32
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | allFieldsFilters |
Type Parameters
T
DeleteNonDefaults<T>(IDbConnection, T)
Delete 1 or more rows using only field with non-default values in the filter. E.g: <p>db.DeleteNonDefaults(new Person { FirstName = "Jimi", Age = 27 })</p>
View Source
public static int DeleteNonDefaults<T>(this IDbConnection dbConn, T nonDefaultsFilter)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | nonDefaultsFilter |
Type Parameters
T
DeleteNonDefaults<T>(IDbConnection, T[])
Delete 1 or more rows in a transaction using only field with non-default values in the filter. E.g: <p>db.DeleteNonDefaults(new Person { FirstName = "Jimi", Age = 27 }, new Person { FirstName = "Janis", Age = 27 })</p>
View Source
public static int DeleteNonDefaults<T>(this IDbConnection dbConn, params T[] nonDefaultsFilters)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | nonDefaultsFilters |
Type Parameters
T
DeleteById<T>(IDbConnection, Object, Action<IDbCommand>)
Delete 1 row by the PrimaryKey. E.g: <p>db.DeleteById<Person>(1)</p>
View Source
public static int DeleteById<T>(this IDbConnection dbConn, object id, Action<IDbCommand> commandFilter = null)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.Object | id |
Action<IDbCommand> | commandFilter |
Type Parameters
T
DeleteById<T>(IDbConnection, Object, UInt64, Action<IDbCommand>)
Delete 1 row by the PrimaryKey where the rowVersion matches the optimistic concurrency field.
Will throw ServiceStack.Data.OptimisticConcurrencyException?text=RowModifiedException
if the
row does not exist or has a different row version.
E.g: <p>db.DeleteById<Person>(1)</p>
View Source
public static void DeleteById<T>(this IDbConnection dbConn, object id, ulong rowVersion, Action<IDbCommand> commandFilter = null)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.Object | id |
System.UInt64 | rowVersion |
Action<IDbCommand> | commandFilter |
Type Parameters
T
DeleteByIds<T>(IDbConnection, IEnumerable)
Delete all rows identified by the PrimaryKeys. E.g: <p>db.DeleteById<Person>(new[] { 1, 2, 3 })</p>
View Source
public static int DeleteByIds<T>(this IDbConnection dbConn, IEnumerable idValues)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable | idValues |
Type Parameters
T
DeleteAll<T>(IDbConnection)
Delete all rows in the generic table type. E.g: <p>db.DeleteAll<Person>()</p>
View Source
public static int DeleteAll<T>(this IDbConnection dbConn)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Type Parameters
T
DeleteAll<T>(IDbConnection, IEnumerable<T>)
Delete all rows provided. E.g: <p>db.DeleteAll<Person>(people)</p>
View Source
public static int DeleteAll<T>(this IDbConnection dbConn, IEnumerable<T> rows)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable<<T>> | rows |
Type Parameters
T
DeleteAll(IDbConnection, Type)
Delete all rows in the runtime table type. E.g: <p>db.DeleteAll(typeof(Person))</p>
View Source
public static int DeleteAll(this IDbConnection dbConn, Type tableType)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Type | tableType |
Delete<T>(IDbConnection, String, Object)
Delete rows using a SqlFormat filter. E.g: <p>db.Delete<Person>("Age > @age", new { age = 42 })</p>
View Source
public static int Delete<T>(this IDbConnection dbConn, string sqlFilter, object anonType)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.String | sqlFilter |
System.Object | anonType |
Type Parameters
T
Delete(IDbConnection, Type, String, Object)
Delete rows using a SqlFormat filter. E.g: <p>db.Delete(typeof(Person), "Age > @age", new { age = 42 })</p>
View Source
public static int Delete(this IDbConnection dbConn, Type tableType, string sqlFilter, object anonType)
Returns
System.Int32
: number of rows deleted
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Type | tableType |
System.String | sqlFilter |
System.Object | anonType |
Save<T>(IDbConnection, T, Boolean)
Insert a new row or update existing row. Returns true if a new row was inserted. Optional references param decides whether to save all related references as well. E.g: <p>db.Save(customer, references:true)</p>
View Source
public static bool Save<T>(this IDbConnection dbConn, T obj, bool references = false)
Returns
System.Boolean
: true if a row was inserted; false if it was updated
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
System.Boolean | references |
Type Parameters
T
Save<T>(IDbConnection, T[])
Insert new rows or update existing rows. Return number of rows added E.g: <p>db.Save(new Person { Id = 10, FirstName = "Amy", LastName = "Winehouse", Age = 27 })</p>
View Source
public static int Save<T>(this IDbConnection dbConn, params T[] objs)
Returns
System.Int32
: number of rows added
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T>[] | objs |
Type Parameters
T
SaveAll<T>(IDbConnection, IEnumerable<T>)
Insert new rows or update existing rows. Return number of rows added E.g: <p>db.SaveAll(new [] { new Person { Id = 10, FirstName = "Amy", LastName = "Winehouse", Age = 27 } })</p>
View Source
public static int SaveAll<T>(this IDbConnection dbConn, IEnumerable<T> objs)
Returns
System.Int32
: number of rows added
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
IEnumerable<<T>> | objs |
Type Parameters
T
SaveAllReferences<T>(IDbConnection, T)
Populates all related references on the instance with its primary key and saves them. Uses '(T)Id' naming convention. E.g: <p>db.SaveAllReferences(customer)</p>
View Source
public static void SaveAllReferences<T>(this IDbConnection dbConn, T instance)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | instance |
Type Parameters
T
SaveReferences<T, TRef>(IDbConnection, T, TRef[])
Populates the related references with the instance primary key and saves them. Uses '(T)Id' naming convention. E.g: <p>db.SaveReference(customer, customer.Orders)</p>
View Source
public static void SaveReferences<T, TRef>(this IDbConnection dbConn, T instance, params TRef[] refs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | instance |
<TRef>[] | refs |
Type Parameters
T
TRef
SaveReferences<T, TRef>(IDbConnection, T, List<TRef>)
Populates the related references with the instance primary key and saves them. Uses '(T)Id' naming convention. E.g: <p>db.SaveReference(customer, customer.Orders)</p>
View Source
public static void SaveReferences<T, TRef>(this IDbConnection dbConn, T instance, List<TRef> refs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | instance |
List<<TRef>> | refs |
Type Parameters
T
TRef
SaveReferences<T, TRef>(IDbConnection, T, IEnumerable<TRef>)
Populates the related references with the instance primary key and saves them. Uses '(T)Id' naming convention. E.g: <p>db.SaveReferences(customer, customer.Orders)</p>
View Source
public static void SaveReferences<T, TRef>(this IDbConnection dbConn, T instance, IEnumerable<TRef> refs)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | instance |
IEnumerable<<TRef>> | refs |
Type Parameters
T
TRef
GetRowVersion<T>(IDbConnection, Object)
View Source
public static object GetRowVersion<T>(this IDbConnection dbConn, object id)
Returns
System.Object
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
System.Object | id |
Type Parameters
T
GetRowVersion(IDbConnection, Type, Object)
View Source
public static object GetRowVersion(this IDbConnection dbConn, Type modelType, object id)
Returns
System.Object
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
Type | modelType |
System.Object | id |
ExecuteProcedure<T>(IDbConnection, T)
View Source
public static void ExecuteProcedure<T>(this IDbConnection dbConn, T obj)
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | obj |
Type Parameters
T
ToUpdateStatement<T>(IDbConnection, T, ICollection<String>)
Generates inline UPDATE SQL Statement
View Source
public static string ToUpdateStatement<T>(this IDbConnection dbConn, T item, ICollection<string> updateFields = null)
Returns
System.String
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | item |
ICollection<System.String> | updateFields |
Type Parameters
T
ToInsertStatement<T>(IDbConnection, T, ICollection<String>)
Generates inline INSERT SQL Statement
View Source
public static string ToInsertStatement<T>(this IDbConnection dbConn, T item, ICollection<string> insertFields = null)
Returns
System.String
Parameters
Type | Name |
---|---|
IDbConnection | dbConn |
<T> | item |
ICollection<System.String> | insertFields |
Type Parameters
T