Skip to main content

OrmLiteReadApi

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

Methods

Select<T>(IDbConnection)

Returns results from the active connection.

View Source
Declaration
public static List<T> Select<T>(this IDbConnection dbConn)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
Type Parameters
  • T

Select<T>(IDbConnection, String)

Returns results from using sql. E.g: <p>db.Select<Person>("Age > 40")</p> <p>db.Select<Person>("SELECT * FROM Person WHERE Age > 40")</p>

View Source
Declaration
public static List<T> Select<T>(this IDbConnection dbConn, string sql)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Type Parameters
  • T

Select<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns results from using sql. E.g: <p>db.Select<Person>("SELECT * FROM Person WHERE Age > @age", new[] { db.CreateParam("age", 40) })</p>

View Source
Declaration
public static List<T> Select<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

Select<T>(IDbConnection, String, Object)

Returns results from using a parameterized query. E.g: <p>db.Select<Person>("Age > @age", new { age = 40})</p> <p>db.Select<Person>("SELECT * FROM Person WHERE Age > @age", new { age = 40})</p>

View Source
Declaration
public static List<T> Select<T>(this IDbConnection dbConn, string sql, object anonType)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

Select<T>(IDbConnection, String, Dictionary<String, Object>)

Returns results from using a parameterized query. E.g: <p>db.Select<Person>("Age > @age", new Dictionary<string, object> { { "age", 40 } })</p> <p>db.Select<Person>("SELECT * FROM Person WHERE Age > @age", new Dictionary<string, object> { { "age", 40 } })</p>

View Source
Declaration
public static List<T> Select<T>(this IDbConnection dbConn, string sql, Dictionary<string, object> dict)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Dictionary<System.String,System.Object>dict
Type Parameters
  • T

Select<TModel>(IDbConnection, Type, String, Object)

Returns a partial subset of results from the specified tableType. E.g: <p>db.Select<EntityWithId>(typeof(Person))</p> <p></p>

View Source
Declaration
public static List<TModel> Select<TModel>(this IDbConnection dbConn, Type fromTableType, string sql, object anonType)
Returns

List<<TModel>>

Parameters
TypeName
IDbConnectiondbConn
TypefromTableType
System.Stringsql
System.ObjectanonType
Type Parameters
  • TModel

Select<TModel>(IDbConnection, Type)

Returns a partial subset of results from the specified tableType. E.g: <p>db.Select<EntityWithId>(typeof(Person))</p> <p></p>

View Source
Declaration
public static List<TModel> Select<TModel>(this IDbConnection dbConn, Type fromTableType)
Returns

List<<TModel>>

Parameters
TypeName
IDbConnectiondbConn
TypefromTableType
Type Parameters
  • TModel

Where<T>(IDbConnection, String, Object)

Returns results from using a single name, value filter. E.g: <p>db.Where<Person>("Age", 27)</p>

View Source
Declaration
public static List<T> Where<T>(this IDbConnection dbConn, string name, object value)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringname
System.Objectvalue
Type Parameters
  • T

Where<T>(IDbConnection, Object)

Returns results from using an anonymous type filter. E.g: <p>db.Where<Person>(new { Age = 27 })</p>

View Source
Declaration
public static List<T> Where<T>(this IDbConnection dbConn, object anonType)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
Type Parameters
  • T

SelectByIds<T>(IDbConnection, IEnumerable)

Returns results using the supplied primary key ids. E.g: <p>db.SelectByIds<Person>(new[] { 1, 2, 3 })</p>

View Source
Declaration
public static List<T> SelectByIds<T>(this IDbConnection dbConn, IEnumerable idValues)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
IEnumerableidValues
Type Parameters
  • T

SelectNonDefaults<T>(IDbConnection, T)

Query results using the non-default values in the supplied partially populated POCO example. E.g: <p>db.SelectNonDefaults(new Person { Id = 1 })</p>

View Source
Declaration
public static List<T> SelectNonDefaults<T>(this IDbConnection dbConn, T filter)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
<T>filter
Type Parameters
  • T

SelectNonDefaults<T>(IDbConnection, String, T)

Query results using the non-default values in the supplied partially populated POCO example. E.g: <p>db.SelectNonDefaults("Age > @Age", new Person { Age = 42 })</p>

View Source
Declaration
public static List<T> SelectNonDefaults<T>(this IDbConnection dbConn, string sql, T filter)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
<T>filter
Type Parameters
  • T

SelectLazy<T>(IDbConnection)

Returns a lazily loaded stream of results. E.g: <p>db.SelectLazy<Person>()</p>

View Source
Declaration
public static IEnumerable<T> SelectLazy<T>(this IDbConnection dbConn)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
Type Parameters
  • T

SelectLazy<T>(IDbConnection, String, Object)

Returns a lazily loaded stream of results using a parameterized query. E.g: <p>db.SelectLazy<Person>("Age > @age", new { age = 40 })</p>

View Source
Declaration
public static IEnumerable<T> SelectLazy<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SelectLazy<T>(IDbConnection, SqlExpression<T>)

Returns a lazily loaded stream of results using a parameterized query. E.g: <p>db.SelectLazy(db.From<Person>().Where(x => x == 40))</p>

View Source
Declaration
public static IEnumerable<T> SelectLazy<T>(this IDbConnection dbConn, SqlExpression<T> expression)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.SqlExpression<T>expression
Type Parameters
  • T

WhereLazy<T>(IDbConnection, Object)

Returns a stream of results that are lazily loaded using a parameterized query. E.g: <p>db.WhereLazy<Person>(new { Age = 27 })</p>

View Source
Declaration
public static IEnumerable<T> WhereLazy<T>(this IDbConnection dbConn, object anonType)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
Type Parameters
  • T

Single<T>(IDbConnection, Object)

Returns the first result using a parameterized query. E.g: <p>db.Single<Person>(new { Age = 42 })</p>

View Source
Declaration
public static T Single<T>(this IDbConnection dbConn, object anonType)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
Type Parameters
  • T

Single<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns results from using a single name, value filter. E.g: <p>db.Single<Person>("Age = @age", new[] { db.CreateParam("age",40) })</p>

View Source
Declaration
public static T Single<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

Single<T>(IDbConnection, String, Object)

Returns results from using a single name, value filter. E.g: <p>db.Single<Person>("Age = @age", new { age = 42 })</p>

View Source
Declaration
public static T Single<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SingleById<T>(IDbConnection, Object)

Returns the first result using a primary key id. E.g: <p>db.SingleById<Person>(1)</p>

View Source
Declaration
public static T SingleById<T>(this IDbConnection dbConn, object idValue)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectidValue
Type Parameters
  • T

SingleWhere<T>(IDbConnection, String, Object)

Returns the first result using a name, value filter. E.g: <p>db.SingleWhere<Person>("Age", 42)</p>

View Source
Declaration
public static T SingleWhere<T>(this IDbConnection dbConn, string name, object value)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringname
System.Objectvalue
Type Parameters
  • T

Scalar<T>(IDbConnection, ISqlExpression)

Returns a single scalar value using an SqlExpression. E.g: <p>db.Column<int>(db.From<Person>().Select(x => Sql.Count("*")).Where(q => q.Age > 40))</p>

View Source
Declaration
public static T Scalar<T>(this IDbConnection dbConn, ISqlExpression sqlExpression)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionsqlExpression
Type Parameters
  • T

Scalar<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns a single scalar value using a parameterized query. E.g: <p>db.Scalar<int>("SELECT COUNT(*) FROM Person WHERE Age > @age", new[] { db.CreateParam("age",40) })</p>

View Source
Declaration
public static T Scalar<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

Scalar<T>(IDbConnection, String, Object)

Returns a single scalar value using a parameterized query. E.g: <p>db.Scalar<int>("SELECT COUNT(*) FROM Person WHERE Age > @age", new { age = 40 })</p>

View Source
Declaration
public static T Scalar<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

Column<T>(IDbConnection, ISqlExpression)

Returns the distinct first column values in a HashSet using an SqlExpression. E.g: <p>db.Column<int>(db.From<Person>().Select(x => x.LastName).Where(q => q.Age == 27))</p>

View Source
Declaration
public static List<T> Column<T>(this IDbConnection dbConn, ISqlExpression query)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionquery
Type Parameters
  • T

Column<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns the first column in a List using a SqlFormat query. E.g: <p>db.Column<string>("SELECT LastName FROM Person WHERE Age = @age", new[] { db.CreateParam("age",27) })</p>

View Source
Declaration
public static List<T> Column<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

ColumnLazy<T>(IDbConnection, ISqlExpression)

Returns the distinct first column values in a HashSet using an SqlExpression. E.g: <p>db.ColumnLazy<int>(db.From<Person>().Select(x => x.LastName).Where(q => q.Age == 27))</p>

View Source
Declaration
public static IEnumerable<T> ColumnLazy<T>(this IDbConnection dbConn, ISqlExpression query)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionquery
Type Parameters
  • T

ColumnLazy<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns the first column in a List using a SqlFormat query. E.g: <p>db.ColumnLazy<string>("SELECT LastName FROM Person WHERE Age = @age", new[] { db.CreateParam("age",27) })</p>

View Source
Declaration
public static IEnumerable<T> ColumnLazy<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

ColumnLazy<T>(IDbConnection, String, Object)

Returns the first column in a List using a SqlFormat query. E.g: <p>db.ColumnLazy<string>("SELECT LastName FROM Person WHERE Age = @age", new { age = 27 })</p>

View Source
Declaration
public static IEnumerable<T> ColumnLazy<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

IEnumerable<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

Column<T>(IDbConnection, String, Object)

Returns the first column in a List using a SqlFormat query. E.g: <p>db.Column<string>("SELECT LastName FROM Person WHERE Age = @age", new { age = 27 })</p>

View Source
Declaration
public static List<T> Column<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

ColumnDistinct<T>(IDbConnection, ISqlExpression)

Returns the distinct first column values in a HashSet using an SqlExpression. E.g: <p>db.ColumnDistinct<int>(db.From<Person>().Select(x => x.Age).Where(q => q.Age < 50))</p>

View Source
Declaration
public static HashSet<T> ColumnDistinct<T>(this IDbConnection dbConn, ISqlExpression query)
Returns

HashSet<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionquery
Type Parameters
  • T

ColumnDistinct<T>(IDbConnection, String, Object)

Returns the distinct first column values in a HashSet using an SqlFormat query. E.g: <p>db.ColumnDistinct<int>("SELECT Age FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static HashSet<T> ColumnDistinct<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

HashSet<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

ColumnDistinct<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns the distinct first column values in a HashSet using an SqlFormat query. E.g: <p>db.ColumnDistinct<int>("SELECT Age FROM Person WHERE Age < @age", new[] { db.CreateParam("age",50) })</p>

View Source
Declaration
public static HashSet<T> ColumnDistinct<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

HashSet<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

Lookup<K, V>(IDbConnection, ISqlExpression)

Returns an Dictionary<K, List<V>> grouping made from the first two columns using an Sql Expression. E.g: <p>db.Lookup<int, string>(db.From<Person>().Select(x => new { x.Age, x.LastName }).Where(q => q.Age < 50))</p>

View Source
Declaration
public static Dictionary<K, List<V>> Lookup<K, V>(this IDbConnection dbConn, ISqlExpression sqlExpression)
Returns

Dictionary<<K>,List<<V>>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionsqlExpression
Type Parameters
  • K
  • V

Lookup<K, V>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns an Dictionary<K, List<V>> grouping made from the first two columns using an parameterized query. E.g: <p>db.Lookup<int, string>("SELECT Age, LastName FROM Person WHERE Age < @age", new[] { db.CreateParam("age",50) })</p>

View Source
Declaration
public static Dictionary<K, List<V>> Lookup<K, V>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

Dictionary<<K>,List<<V>>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • K
  • V

Lookup<K, V>(IDbConnection, String, Object)

Returns an Dictionary<K, List<V>> grouping made from the first two columns using an parameterized query. E.g: <p>db.Lookup<int, string>("SELECT Age, LastName FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static Dictionary<K, List<V>> Lookup<K, V>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

Dictionary<<K>,List<<V>>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • K
  • V

Dictionary<K, V>(IDbConnection, ISqlExpression)

Returns a Dictionary from the first 2 columns: Column 1 (Keys), Column 2 (Values) using an SqlExpression. E.g: <p>db.Dictionary<int, string>(db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50))</p>

View Source
Declaration
public static Dictionary<K, V> Dictionary<K, V>(this IDbConnection dbConn, ISqlExpression query)
Returns

Dictionary<<K>,<V>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionquery
Type Parameters
  • K
  • V

Dictionary<K, V>(IDbConnection, String, Object)

Returns a Dictionary from the first 2 columns: Column 1 (Keys), Column 2 (Values) using sql. E.g: <p>db.Dictionary<int, string>("SELECT Id, LastName FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static Dictionary<K, V> Dictionary<K, V>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

Dictionary<<K>,<V>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • K
  • V

KeyValuePairs<K, V>(IDbConnection, ISqlExpression)

Returns a list KeyValuePairs from the first 2 columns: Column 1 (Keys), Column 2 (Values) using an SqlExpression. E.g: <p>db.KeyValuePairs<int, string>(db.From<Person>().Select(x => new { x.Id, x.LastName }).Where(x => x.Age < 50))</p>

View Source
Declaration
public static List<KeyValuePair<K, V>> KeyValuePairs<K, V>(this IDbConnection dbConn, ISqlExpression query)
Returns

List<KeyValuePair<<K>,<V>>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionquery
Type Parameters
  • K
  • V

KeyValuePairs<K, V>(IDbConnection, String, Object)

Returns a list of KeyValuePairs from the first 2 columns: Column 1 (Keys), Column 2 (Values) using sql. E.g: <p>db.KeyValuePairs<int, string>("SELECT Id, LastName FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static List<KeyValuePair<K, V>> KeyValuePairs<K, V>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

List<KeyValuePair<<K>,<V>>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • K
  • V

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

Returns true if the Query returns any records that match the LINQ expression, E.g: <p>db.Exists<Person>(x => x.Age < 50)</p>

View Source
Declaration
public static bool Exists<T>(this IDbConnection dbConn, Expression<Func<T, bool>> expression)
Returns

System.Boolean

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

Exists<T>(IDbConnection, SqlExpression<T>)

Returns true if the Query returns any records that match the supplied SqlExpression, E.g: <p>db.Exists(db.From<Person>().Where(x => x.Age < 50))</p>

View Source
Declaration
public static bool Exists<T>(this IDbConnection dbConn, SqlExpression<T> expression)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.SqlExpression<T>expression
Type Parameters
  • T

Exists<T>(IDbConnection, Object)

Returns true if the Query returns any records, using an SqlFormat query. E.g: <p>db.Exists<Person>(new { Age = 42 })</p>

View Source
Declaration
public static bool Exists<T>(this IDbConnection dbConn, object anonType)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
Type Parameters
  • T

Exists<T>(IDbConnection, String, Object)

Returns true if the Query returns any records, using a parameterized query. E.g: <p>db.Exists<Person>("Age = @age", new { age = 42 })</p> <p>db.Exists<Person>("SELECT * FROM Person WHERE Age = @age", new { age = 42 })</p>

View Source
Declaration
public static bool Exists<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SqlList<T>(IDbConnection, ISqlExpression)

Returns results from an arbitrary SqlExpression. E.g: <p>db.SqlList<Person>(db.From<Person>().Select("*").Where(q => q.Age < 50))</p>

View Source
Declaration
public static List<T> SqlList<T>(this IDbConnection dbConn, ISqlExpression sqlExpression)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionsqlExpression
Type Parameters
  • T

SqlList<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns results from an arbitrary parameterized raw sql query. E.g: <p>db.SqlList<Person>("EXEC GetRockstarsAged @age", new[] { db.CreateParam("age",50) })</p>

View Source
Declaration
public static List<T> SqlList<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

SqlList<T>(IDbConnection, String, Object)

Returns results from an arbitrary parameterized raw sql query. E.g: <p>db.SqlList<Person>("EXEC GetRockstarsAged @age", new { age = 50 })</p>

View Source
Declaration
public static List<T> SqlList<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SqlList<T>(IDbConnection, String, Dictionary<String, Object>)

Returns results from an arbitrary parameterized raw sql query. E.g: <p>db.SqlList<Person>("EXEC GetRockstarsAged @age", new Dictionary<string, object> { { "age", 42 } })</p>

View Source
Declaration
public static List<T> SqlList<T>(this IDbConnection dbConn, string sql, Dictionary<string, object> dict)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Dictionary<System.String,System.Object>dict
Type Parameters
  • T

SqlList<T>(IDbConnection, String, Action<IDbCommand>)

Returns results from an arbitrary parameterized raw sql query with a dbCmd filter. E.g: <p>db.SqlList<Person>("EXEC GetRockstarsAged @age", dbCmd => ...)</p>

View Source
Declaration
public static List<T> SqlList<T>(this IDbConnection dbConn, string sql, Action<IDbCommand> dbCmdFilter)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Action<IDbCommand>dbCmdFilter
Type Parameters
  • T

SqlProc(IDbConnection, String, Object, Boolean)

Prepare Stored Procedure with Input parameters, optionally populated with Input Params. E.g: <p>var cmd = db.SqlProc("GetRockstarsAged", new { age = 42 })</p>

View Source
Declaration
public static IDbCommand SqlProc(this IDbConnection dbConn, string name, object inParams = null, bool excludeDefaults = false)
Returns

IDbCommand

Parameters
TypeName
IDbConnectiondbConn
System.Stringname
System.ObjectinParams
System.BooleanexcludeDefaults

SqlColumn<T>(IDbConnection, ISqlExpression)

Returns the first column in a List using an SqlExpression. E.g: <p>db.SqlColumn<string>(db.From<Person>().Select(x => x.LastName).Where(q => q.Age < 50))</p>

View Source
Declaration
public static List<T> SqlColumn<T>(this IDbConnection dbConn, ISqlExpression sqlExpression)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionsqlExpression
Type Parameters
  • T

SqlColumn<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns the first column in a List using a parameterized query. E.g: <p>db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new[] { db.CreateParam("age",50) })</p>

View Source
Declaration
public static List<T> SqlColumn<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

SqlColumn<T>(IDbConnection, String, Object)

Returns the first column in a List using a parameterized query. E.g: <p>db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static List<T> SqlColumn<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SqlColumn<T>(IDbConnection, String, Dictionary<String, Object>)

Returns the first column in a List using a parameterized query. E.g: <p>db.SqlColumn<string>("SELECT LastName FROM Person WHERE Age < @age", new Dictionary<string, object> { { "age", 50 } })</p>

View Source
Declaration
public static List<T> SqlColumn<T>(this IDbConnection dbConn, string sql, Dictionary<string, object> dict)
Returns

List<<T>>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Dictionary<System.String,System.Object>dict
Type Parameters
  • T

SqlScalar<T>(IDbConnection, ISqlExpression)

Returns a single Scalar value using an SqlExpression. E.g: <p>db.SqlScalar<int>(db.From<Person>().Select(Sql.Count("*")).Where(q => q.Age < 50))</p>

View Source
Declaration
public static T SqlScalar<T>(this IDbConnection dbConn, ISqlExpression sqlExpression)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
ServiceStack.OrmLite.ISqlExpressionsqlExpression
Type Parameters
  • T

SqlScalar<T>(IDbConnection, String, IEnumerable<IDbDataParameter>)

Returns a single Scalar value using a parameterized query. E.g: <p>db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new[]{ db.CreateParam("age",50) })</p>

View Source
Declaration
public static T SqlScalar<T>(this IDbConnection dbConn, string sql, IEnumerable<IDbDataParameter> sqlParams)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
IEnumerable<IDbDataParameter>sqlParams
Type Parameters
  • T

SqlScalar<T>(IDbConnection, String, Object)

Returns a single Scalar value using a parameterized query. E.g: <p>db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new { age = 50 })</p>

View Source
Declaration
public static T SqlScalar<T>(this IDbConnection dbConn, string sql, object anonType = null)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType
Type Parameters
  • T

SqlScalar<T>(IDbConnection, String, Dictionary<String, Object>)

Returns a single Scalar value using a parameterized query. E.g: <p>db.SqlScalar<int>("SELECT COUNT(*) FROM Person WHERE Age < @age", new Dictionary<string, object> { { "age", 50 } })</p>

View Source
Declaration
public static T SqlScalar<T>(this IDbConnection dbConn, string sql, Dictionary<string, object> dict)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Dictionary<System.String,System.Object>dict
Type Parameters
  • T

LastInsertId(IDbConnection)

Returns the last insert Id made from this connection.

View Source
Declaration
public static long LastInsertId(this IDbConnection dbConn)
Returns

System.Int64

Parameters
TypeName
IDbConnectiondbConn

ExecuteNonQuery(IDbConnection, String)

Executes a raw sql non-query using sql. E.g: <p>var rowsAffected = db.ExecuteNonQuery("UPDATE Person SET LastName={0} WHERE Id={1}".SqlFormat("WaterHouse", 7))</p>

View Source
Declaration
public static int ExecuteNonQuery(this IDbConnection dbConn, string sql)
Returns

System.Int32: number of rows affected

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql

ExecuteNonQuery(IDbConnection, String, Object)

Executes a raw sql non-query using a parameterized query. E.g: <p>var rowsAffected = db.ExecuteNonQuery("UPDATE Person SET LastName=@name WHERE Id=@id", new { name = "WaterHouse", id = 7 })</p>

View Source
Declaration
public static int ExecuteNonQuery(this IDbConnection dbConn, string sql, object anonType)
Returns

System.Int32: number of rows affected

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
System.ObjectanonType

ExecuteNonQuery(IDbConnection, String, Dictionary<String, Object>)

Executes a raw sql non-query using a parameterized query.

View Source
Declaration
public static int ExecuteNonQuery(this IDbConnection dbConn, string sql, Dictionary<string, object> dict)
Returns

System.Int32: number of rows affected

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Dictionary<System.String,System.Object>dict

ExecuteNonQuery(IDbConnection, String, Action<IDbCommand>)

Executes a raw sql non-query using a parameterized query with a dbCmd filter. E.g:

View Source
Declaration
public static int ExecuteNonQuery(this IDbConnection dbConn, string sql, Action<IDbCommand> dbCmdFilter)
Returns

System.Int32: number of rows affected

Parameters
TypeName
IDbConnectiondbConn
System.Stringsql
Action<IDbCommand>dbCmdFilter

SqlProcedure<TOutputModel>(IDbConnection, Object)

Returns results from a Stored Procedure, using a parameterized query.

View Source
Declaration
public static List<TOutputModel> SqlProcedure<TOutputModel>(this IDbConnection dbConn, object anonType)
Returns

List<<TOutputModel>>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
Type Parameters
  • TOutputModel

SqlProcedure<TOutputModel>(IDbConnection, Object, String, Object[])

Returns results from a Stored Procedure using an SqlFormat query. E.g: <p></p>

View Source
Declaration
public static List<TOutputModel> SqlProcedure<TOutputModel>(this IDbConnection dbConn, object anonType, string sqlFilter, params object[] filterParams)
where TOutputModel : new()
Returns

List<<TOutputModel>>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectanonType
System.StringsqlFilter
System.Object[]filterParams
Type Parameters
  • TOutputModel

LongScalar(IDbConnection)

Returns the scalar result as a long.

View Source
Declaration
public static long LongScalar(this IDbConnection dbConn)
Returns

System.Int64

Parameters
TypeName
IDbConnectiondbConn

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

Returns the first result with all its references loaded, using a primary key id. E.g: <p>db.LoadSingleById<Person>(1, include = new[]{ "Address" })</p>

View Source
Declaration
public static T LoadSingleById<T>(this IDbConnection dbConn, object idValue, string[] include = null)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectidValue
System.String[]include
Type Parameters
  • T

LoadSingleById<T>(IDbConnection, Object, Expression<Func<T, Object>>)

Returns the first result with all its references loaded, using a primary key id. E.g: <p>db.LoadSingleById<Person>(1, include = x => new{ x.Address })</p>

View Source
Declaration
public static T LoadSingleById<T>(this IDbConnection dbConn, object idValue, Expression<Func<T, object>> include)
Returns

<T>

Parameters
TypeName
IDbConnectiondbConn
System.ObjectidValue
Expression<Func<<T>,System.Object>>include
Type Parameters
  • T

LoadReferences<T>(IDbConnection, T)

Loads all the related references onto the instance. E.g: <p>db.LoadReferences(customer)</p>

View Source
Declaration
public static void LoadReferences<T>(this IDbConnection dbConn, T instance)
Parameters
TypeName
IDbConnectiondbConn
<T>instance
Type Parameters
  • T