Skip to main content

OrmLiteSchemaApi

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

Methods

TableExists(IDbConnection, String, String)

Checks whether a Table Exists. E.g: <p>db.TableExists("Person")</p>

View Source
Declaration
public static bool TableExists(this IDbConnection dbConn, string tableName, string schema = null)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
System.StringtableName
System.Stringschema

TableExistsAsync(IDbConnection, String, String, CancellationToken)

Checks whether a Table Exists. E.g: <p>db.TableExistsAsync("Person")</p>

View Source
Declaration
public static Task<bool> TableExistsAsync(this IDbConnection dbConn, string tableName, string schema = null, CancellationToken token = null)
Returns

Task<System.Boolean>

Parameters
TypeName
IDbConnectiondbConn
System.StringtableName
System.Stringschema
CancellationTokentoken

TableExists<T>(IDbConnection)

Checks whether a Table Exists. E.g: <p>db.TableExists<Person>()</p>

View Source
Declaration
public static bool TableExists<T>(this IDbConnection dbConn)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
Type Parameters
  • T

TableExistsAsync<T>(IDbConnection, CancellationToken)

Checks whether a Table Exists. E.g: <p>db.TableExistsAsync<Person>()</p>

View Source
Declaration
public static Task<bool> TableExistsAsync<T>(this IDbConnection dbConn, CancellationToken token = null)
Returns

Task<System.Boolean>

Parameters
TypeName
IDbConnectiondbConn
CancellationTokentoken
Type Parameters
  • T

ColumnExists(IDbConnection, String, String, String)

Checks whether a Table Column Exists. E.g: <p>db.ColumnExists("Age", "Person")</p>

View Source
Declaration
public static bool ColumnExists(this IDbConnection dbConn, string columnName, string tableName, string schema = null)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
System.StringcolumnName
System.StringtableName
System.Stringschema

ColumnExistsAsync(IDbConnection, String, String, String, CancellationToken)

Checks whether a Table Column Exists. E.g: <p>db.ColumnExistsAsync("Age", "Person")</p>

View Source
Declaration
public static Task<bool> ColumnExistsAsync(this IDbConnection dbConn, string columnName, string tableName, string schema = null, CancellationToken token = null)
Returns

Task<System.Boolean>

Parameters
TypeName
IDbConnectiondbConn
System.StringcolumnName
System.StringtableName
System.Stringschema
CancellationTokentoken

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

Checks whether a Table Column Exists. E.g: <p>db.ColumnExists<Person>(x => x.Age)</p>

View Source
Declaration
public static bool ColumnExists<T>(this IDbConnection dbConn, Expression<Func<T, object>> field)
Returns

System.Boolean

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

ColumnExistsAsync<T>(IDbConnection, Expression<Func<T, Object>>, CancellationToken)

Checks whether a Table Column Exists. E.g: <p>db.ColumnExistsAsync<Person>(x => x.Age)</p>

View Source
Declaration
public static Task<bool> ColumnExistsAsync<T>(this IDbConnection dbConn, Expression<Func<T, object>> field, CancellationToken token = null)
Returns

Task<System.Boolean>

Parameters
TypeName
IDbConnectiondbConn
Expression<Func<<T>,System.Object>>field
CancellationTokentoken
Type Parameters
  • T

CreateSchema<T>(IDbConnection)

Create a DB Schema from the Schema attribute on the generic type. E.g: <p>db.CreateSchema<Person>() //default</p>

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

CreateSchema(IDbConnection, String)

Create a DB Schema. E.g: <p>db.CreateSchema("schemaName")</p>

View Source
Declaration
public static bool CreateSchema(this IDbConnection dbConn, string schemaName)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
System.StringschemaName

CreateTables(IDbConnection, Boolean, Type[])

Create DB Tables from the schemas of runtime types. E.g: <p>db.CreateTables(typeof(Table1), typeof(Table2))</p>

View Source
Declaration
public static void CreateTables(this IDbConnection dbConn, bool overwrite, params Type[] tableTypes)
Parameters
TypeName
IDbConnectiondbConn
System.Booleanoverwrite
Type[]tableTypes

CreateTable(IDbConnection, Boolean, Type)

Create DB Table from the schema of the runtime type. Use overwrite to drop existing Table. E.g: <p>db.CreateTable(true, typeof(Table))</p>

View Source
Declaration
public static void CreateTable(this IDbConnection dbConn, bool overwrite, Type modelType)
Parameters
TypeName
IDbConnectiondbConn
System.Booleanoverwrite
TypemodelType

CreateTableIfNotExists(IDbConnection, Type[])

Only Create new DB Tables from the schemas of runtime types if they don't already exist. E.g: <p>db.CreateTableIfNotExists(typeof(Table1), typeof(Table2))</p>

View Source
Declaration
public static void CreateTableIfNotExists(this IDbConnection dbConn, params Type[] tableTypes)
Parameters
TypeName
IDbConnectiondbConn
Type[]tableTypes

DropAndCreateTables(IDbConnection, Type[])

Drop existing DB Tables and re-create them from the schemas of runtime types. E.g: <p>db.DropAndCreateTables(typeof(Table1), typeof(Table2))</p>

View Source
Declaration
public static void DropAndCreateTables(this IDbConnection dbConn, params Type[] tableTypes)
Parameters
TypeName
IDbConnectiondbConn
Type[]tableTypes

CreateTable<T>(IDbConnection, Boolean)

Create a DB Table from the generic type. Use overwrite to drop the existing table or not. E.g: <p>db.CreateTable<Person>(overwrite=false) //default</p> <p>db.CreateTable<Person>(overwrite=true)</p>

View Source
Declaration
public static void CreateTable<T>(this IDbConnection dbConn, bool overwrite = false)
Parameters
TypeName
IDbConnectiondbConn
System.Booleanoverwrite
Type Parameters
  • T

CreateTableIfNotExists<T>(IDbConnection)

Only create a DB Table from the generic type if it doesn't already exist. E.g: <p>db.CreateTableIfNotExists<Person>()</p>

View Source
Declaration
public static bool CreateTableIfNotExists<T>(this IDbConnection dbConn)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
Type Parameters
  • T

CreateTableIfNotExists(IDbConnection, Type)

Only create a DB Table from the runtime type if it doesn't already exist. E.g: <p>db.CreateTableIfNotExists(typeof(Person))</p>

View Source
Declaration
public static bool CreateTableIfNotExists(this IDbConnection dbConn, Type modelType)
Returns

System.Boolean

Parameters
TypeName
IDbConnectiondbConn
TypemodelType

DropAndCreateTable<T>(IDbConnection)

Drop existing table if exists and re-create a DB Table from the generic type. E.g: <p>db.DropAndCreateTable<Person>()</p>

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

DropAndCreateTable(IDbConnection, Type)

Drop existing table if exists and re-create a DB Table from the runtime type. E.g: <p>db.DropAndCreateTable(typeof(Person))</p>

View Source
Declaration
public static void DropAndCreateTable(this IDbConnection dbConn, Type modelType)
Parameters
TypeName
IDbConnectiondbConn
TypemodelType

DropTables(IDbConnection, Type[])

Drop any existing tables from their runtime types. E.g: <p>db.DropTables(typeof(Table1),typeof(Table2))</p>

View Source
Declaration
public static void DropTables(this IDbConnection dbConn, params Type[] tableTypes)
Parameters
TypeName
IDbConnectiondbConn
Type[]tableTypes

DropTable(IDbConnection, Type)

Drop any existing tables from the runtime type. E.g: <p>db.DropTable(typeof(Person))</p>

View Source
Declaration
public static void DropTable(this IDbConnection dbConn, Type modelType)
Parameters
TypeName
IDbConnectiondbConn
TypemodelType

DropTable<T>(IDbConnection)

Drop any existing tables from the generic type. E.g: <p>db.DropTable<Person>()</p>

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

GetSchemas(IDbConnection)

Get a list of available user schemas for this connection

View Source
Declaration
public static List<string> GetSchemas(this IDbConnection dbConn)
Returns

List<System.String>

Parameters
TypeName
IDbConnectiondbConn

GetSchemaTables(IDbConnection)

Get available user Schemas and their tables for this connection

View Source
Declaration
public static Dictionary<string, List<string>> GetSchemaTables(this IDbConnection dbConn)
Returns

Dictionary<System.String,List<System.String>>

Parameters
TypeName
IDbConnectiondbConn

Migrate<T>(IDbConnection)

Alter tables by adding properties for missing columns and removing properties annotated with [RemoveColumn]

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

Revert<T>(IDbConnection)

Apply schema changes by Migrate in reverse to revert changes

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