C# Class Massive.DynamicModel

A class that wraps your database table in Dynamic Funtime
Datei anzeigen Open project: johnmbaughman/SQLiteConverter Class Usage Examples

Public Properties

Property Type Description
Errors IList

Public Methods

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

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

BeforeDelete ( dynamic item ) : bool
BeforeSave ( dynamic item ) : bool
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

CreateDeleteCommand ( string where = "", object key = null ) : DbCommand

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

CreateFrom ( NameValueCollection coll ) : dynamic

Creates a new Expando from a Form POST - white listed against the columns in the DB

CreateInsertCommand ( dynamic expando ) : DbCommand
CreateUpdateCommand ( dynamic expando, object key ) : DbCommand

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

DefaultTo ( string key, object value, dynamic item ) : void
DefaultValue ( dynamic column ) : dynamic

Gets a default value for the column

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

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

Deleted ( dynamic item ) : void
DynamicModel ( ConnectionStringSettings connectionStringSettings, string tableName = "", string primaryKeyField = "" ) : System
DynamicModel ( string connectionStringName, string tableName = "", string primaryKeyField = "", string descriptorField = "" ) : System
Execute ( DbCommand command ) : int
Execute ( IEnumerable commands ) : int

Executes a series of DBCommands in a transaction

Execute ( string sql ) : int
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 ) : dynamic

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

Inserted ( dynamic item ) : void
IsValid ( dynamic item ) : bool
ItemAsDictionary ( ExpandoObject item ) : object>.IDictionary

This will return an Expando as a Dictionary

ItemContainsKey ( string key, ExpandoObject item ) : bool
KeyValues ( string orderBy = "" ) : object>.IDictionary

This will return a string/object dictionary for dropdowns etc

Open ( ConnectionStringSettings connectionStringSettings ) : DynamicModel
Open ( string connectionStringName ) : DynamicModel
OpenConnection ( ) : DbConnection

Returns and OpenConnection

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

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

Paged ( string sql, string primaryKey, string where = "", string orderBy = "", string columns = "*", int pageSize = 20, int currentPage = 1 ) : dynamic
Query ( string sql ) : IEnumerable

Enumerates the reader yielding the result - thanks to Jeroen Haegebaert

Query ( string sql, DbConnection connection ) : IEnumerable
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

Scalar ( string sql ) : object

Returns a single result

Single ( object key, string columns = "*" ) : dynamic

Returns a single row from the database

Single ( string where ) : dynamic

Returns a single row from the database

TryInvokeMember ( InvokeMemberBinder binder, object args, object &result ) : bool

A helpful query tool

Update ( object o, object key ) : 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

Updated ( dynamic item ) : void
Validate ( dynamic item ) : void
ValidateIsCurrency ( object value, string message = "Should be money" ) : void
ValidatesNumericalityOf ( object value, string message = "Should be a number" ) : void
ValidatesPresenceOf ( object value, string message = "Required" ) : void

Private Methods

Method Description
BuildPagedResult ( string sql = "", string primaryKeyField = "", string where = "", string orderBy = "", string columns = "*", int pageSize = 20, int currentPage = 1 ) : dynamic
BuildSelect ( string where, string orderBy, int limit ) : string
CreateCommand ( string sql, DbConnection conn ) : DbCommand

Creates a DBCommand that you can use for loving your database.

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 ( string where = "", string orderBy = "", int limit, string columns = "*" ) : IEnumerable
where string
orderBy string
limit int
columns string
return IEnumerable

BeforeDelete() public method

public BeforeDelete ( dynamic item ) : bool
item dynamic
return bool

BeforeSave() public method

public BeforeSave ( dynamic item ) : bool
item dynamic
return bool

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

CreateDeleteCommand() public method

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

CreateFrom() public method

Creates a new Expando from a Form POST - white listed against the columns in the DB
public CreateFrom ( NameValueCollection coll ) : dynamic
coll NameValueCollection
return dynamic

CreateInsertCommand() public method

public CreateInsertCommand ( dynamic expando ) : DbCommand
expando dynamic
return DbCommand

CreateUpdateCommand() public method

Creates a command for use with transactions - internal stuff mostly, but here for you to play with
public CreateUpdateCommand ( dynamic expando, object key ) : DbCommand
expando dynamic
key object
return DbCommand

DefaultTo() public method

public DefaultTo ( string key, object value, dynamic item ) : void
key string
value object
item dynamic
return void

DefaultValue() public method

Gets a default value for the column
public DefaultValue ( dynamic column ) : dynamic
column dynamic
return dynamic

Delete() public method

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

Deleted() public method

public Deleted ( dynamic item ) : void
item dynamic
return void

DynamicModel() public method

public DynamicModel ( ConnectionStringSettings connectionStringSettings, string tableName = "", string primaryKeyField = "" ) : System
connectionStringSettings ConnectionStringSettings
tableName string
primaryKeyField string
return System

DynamicModel() public method

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

Execute() public method

public Execute ( DbCommand command ) : int
command DbCommand
return int

Execute() public method

Executes a series of DBCommands in a transaction
public Execute ( IEnumerable commands ) : int
commands IEnumerable
return int

Execute() public method

public Execute ( string sql ) : int
sql string
return int

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 ) : dynamic
o object
return dynamic

Inserted() public method

public Inserted ( dynamic item ) : void
item dynamic
return void

IsValid() public method

public IsValid ( dynamic item ) : bool
item dynamic
return bool

ItemAsDictionary() public method

This will return an Expando as a Dictionary
public ItemAsDictionary ( ExpandoObject item ) : object>.IDictionary
item ExpandoObject
return object>.IDictionary

ItemContainsKey() public method

public ItemContainsKey ( string key, ExpandoObject item ) : bool
key string
item ExpandoObject
return bool

KeyValues() public method

This will return a string/object dictionary for dropdowns etc
public KeyValues ( string orderBy = "" ) : object>.IDictionary
orderBy string
return object>.IDictionary

Open() public static method

public static Open ( ConnectionStringSettings connectionStringSettings ) : DynamicModel
connectionStringSettings ConnectionStringSettings
return DynamicModel

Open() public static method

public static Open ( string connectionStringName ) : DynamicModel
connectionStringName string
return DynamicModel

OpenConnection() public method

Returns and OpenConnection
public OpenConnection ( ) : DbConnection
return DbConnection

Paged() public method

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

Paged() public method

public Paged ( string sql, string primaryKey, string where = "", string orderBy = "", string columns = "*", int pageSize = 20, int currentPage = 1 ) : dynamic
sql string
primaryKey string
where string
orderBy string
columns string
pageSize int
currentPage int
return dynamic

Query() public method

Enumerates the reader yielding the result - thanks to Jeroen Haegebaert
public Query ( string sql ) : IEnumerable
sql string
return IEnumerable

Query() public method

public Query ( string sql, DbConnection connection ) : IEnumerable
sql string
connection DbConnection
return IEnumerable

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

Scalar() public method

Returns a single result
public Scalar ( string sql ) : object
sql string
return object

Single() public method

Returns a single row from the database
public Single ( object key, string columns = "*" ) : dynamic
key object
columns string
return dynamic

Single() public method

Returns a single row from the database
public Single ( string where ) : dynamic
where string
return dynamic

TryInvokeMember() public method

A helpful query tool
public TryInvokeMember ( InvokeMemberBinder binder, object args, object &result ) : bool
binder InvokeMemberBinder
args object
result object
return bool

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 ) : int
o object
key object
return int

Updated() public method

public Updated ( dynamic item ) : void
item dynamic
return void

Validate() public method

public Validate ( dynamic item ) : void
item dynamic
return void

ValidateIsCurrency() public method

public ValidateIsCurrency ( object value, string message = "Should be money" ) : void
value object
message string
return void

ValidatesNumericalityOf() public method

public ValidatesNumericalityOf ( object value, string message = "Should be a number" ) : void
value object
message string
return void

ValidatesPresenceOf() public method

public ValidatesPresenceOf ( object value, string message = "Required" ) : void
value object
message string
return void

Property Details

Errors public_oe property

public IList Errors
return IList