C# Class Passive.DynamicModel

A class that wraps your database table in Dynamic Funtime
Mostra file Open project: Talljoe/Passive

Public Methods

Method Description
All ( object where = null, string orderBy = "", int limit, object columns = null ) : IEnumerable

Returns all records complying with the passed-in WHERE clause and arguments, ordered as specified, limited (TOP) by limit.

BuildCommands ( ) : List

Builds a set of Insert and Update commands based on the passed-on objects. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs

BuildCommandsWithWhitelist ( object whitelist ) : List

Builds a set of Insert and Update commands based on the passed-on objects. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs

Delete ( object key = null, object where = null ) : int

Removes one or more records from the DB according to the passed-in WHERE

DynamicModel ( DynamicDatabase database, string tableName = "", string primaryKeyField = "" ) : System

Initializes a new instance of the DynamicModel class.

DynamicModel ( string connectionStringName = "", string tableName = "", string primaryKeyField = "" ) : System

Initializes a new instance of the DynamicModel class.

GetPrimaryKey ( object o ) : object

If the object passed in has a property with the same name as your PrimaryKeyField it is returned here.

HasPrimaryKey ( object o ) : bool

Conventionally introspects the object passed in for a field that looks like a PK. If you've named your PrimaryKeyField, this becomes easy

Insert ( object o, object whitelist = null ) : object

Adds a record to the database. You can pass in an Anonymous object, an ExpandoObject, A regular old POCO, or a NameValueColletion from a Request.Form or Request.QueryString

Paged ( object where = null, string orderBy = "", object columns = null, int pageSize = 20, int currentPage = 1 ) : dynamic

Returns a dynamic PagedResult. Result properties are Items, TotalPages, and TotalRecords.

Save ( ) : int

Executes a set of objects as Insert or Update commands based on their property settings, within a transaction. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs

SaveWithWhitelist ( object whitelist ) : int

Executes a set of objects as Insert or Update commands based on their property settings, within a transaction. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs

Single ( object key = null, object where = null, object columns = null ) : dynamic

Returns a single row from the database

Update ( object o, object key, object whitelist = null ) : int

Updates a record in the database. You can pass in an Anonymous object, an ExpandoObject, A regular old POCO, or a NameValueCollection from a Request.Form or Request.QueryString

Protected Methods

Method Description
CreateDeleteCommand ( object key = null, object where = null ) : DynamicCommand

Removes one or more records from the DB according to the passed-in WHERE

CreateInsertCommand ( object o, object whitelist = null ) : DynamicCommand

Creates a command for use with transactions - internal stuff mostly, but here for you to play with

CreateUpdateCommand ( object o, object key, object whitelist = null ) : DynamicCommand

Creates a command for use with transactions - internal stuff mostly, but here for you to play with

Private Methods

Method Description
FilterItems ( object o, object whitelist ) : object>>.IEnumerable
GetColumn ( string propertyName, string columnName ) : string
GetColumns ( object columns ) : string
GetContext ( string method ) : string
GetWhereInfo ( object where, object key, IEnumerable args ) : WhereInfo
MapPrimaryKey ( object o ) : string

Method Details

All() public method

Returns all records complying with the passed-in WHERE clause and arguments, ordered as specified, limited (TOP) by limit.
public All ( object where = null, string orderBy = "", int limit, object columns = null ) : IEnumerable
where object
orderBy string
limit int
columns object
return IEnumerable

BuildCommands() public method

Builds a set of Insert and Update commands based on the passed-on objects. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs
public BuildCommands ( ) : List
return List

BuildCommandsWithWhitelist() public method

Builds a set of Insert and Update commands based on the passed-on objects. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs
public BuildCommandsWithWhitelist ( object whitelist ) : List
whitelist object
return List

CreateDeleteCommand() protected method

Removes one or more records from the DB according to the passed-in WHERE
protected CreateDeleteCommand ( object key = null, object where = null ) : DynamicCommand
key object
where object
return DynamicCommand

CreateInsertCommand() protected method

Creates a command for use with transactions - internal stuff mostly, but here for you to play with
protected CreateInsertCommand ( object o, object whitelist = null ) : DynamicCommand
o object
whitelist object
return DynamicCommand

CreateUpdateCommand() protected method

Creates a command for use with transactions - internal stuff mostly, but here for you to play with
protected CreateUpdateCommand ( object o, object key, object whitelist = null ) : DynamicCommand
o object
key object
whitelist object
return DynamicCommand

Delete() public method

Removes one or more records from the DB according to the passed-in WHERE
public Delete ( object key = null, object where = null ) : int
key object
where object
return int

DynamicModel() public method

Initializes a new instance of the DynamicModel class.
public DynamicModel ( DynamicDatabase database, string tableName = "", string primaryKeyField = "" ) : System
database DynamicDatabase The database.
tableName string Name of the table.
primaryKeyField string The primary key field.
return System

DynamicModel() public method

Initializes a new instance of the DynamicModel class.
public DynamicModel ( string connectionStringName = "", string tableName = "", string primaryKeyField = "" ) : System
connectionStringName string Name of the connection string.
tableName string Name of the table.
primaryKeyField string The primary key field.
return System

GetPrimaryKey() public method

If the object passed in has a property with the same name as your PrimaryKeyField it is returned here.
public GetPrimaryKey ( object o ) : object
o object
return object

HasPrimaryKey() public method

Conventionally introspects the object passed in for a field that looks like a PK. If you've named your PrimaryKeyField, this becomes easy
public HasPrimaryKey ( object o ) : bool
o object
return bool

Insert() public method

Adds a record to the database. You can pass in an Anonymous object, an ExpandoObject, A regular old POCO, or a NameValueColletion from a Request.Form or Request.QueryString
public Insert ( object o, object whitelist = null ) : object
o object
whitelist object
return object

Paged() public method

Returns a dynamic PagedResult. Result properties are Items, TotalPages, and TotalRecords.
public Paged ( object where = null, string orderBy = "", object columns = null, int pageSize = 20, int currentPage = 1 ) : dynamic
where object
orderBy string
columns object
pageSize int
currentPage int
return dynamic

Save() public method

Executes a set of objects as Insert or Update commands based on their property settings, within a transaction. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs
public Save ( ) : int
return int

SaveWithWhitelist() public method

Executes a set of objects as Insert or Update commands based on their property settings, within a transaction. These objects can be POCOs, Anonymous, NameValueCollections, or Expandos. Objects With a PK property (whatever PrimaryKeyField is set to) will be created at UPDATEs
public SaveWithWhitelist ( object whitelist ) : int
whitelist object
return int

Single() public method

Returns a single row from the database
public Single ( object key = null, object where = null, object columns = null ) : dynamic
key object
where object
columns object
return dynamic

Update() public method

Updates a record in the database. You can pass in an Anonymous object, an ExpandoObject, A regular old POCO, or a NameValueCollection from a Request.Form or Request.QueryString
public Update ( object o, object key, object whitelist = null ) : int
o object
key object
whitelist object
return int