C# Class Massive.DynamicModel

A class that wraps your database table in Dynamic Funtime
Afficher le fichier Open project: johnmbaughman/SQLiteConverter Class Usage Examples

Méthodes publiques

Свойство Type Description
Errors IList

Méthodes publiques

Méthode 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

Méthode 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 méthode

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
Résultat IEnumerable

BeforeDelete() public méthode

public BeforeDelete ( dynamic item ) : bool
item dynamic
Résultat bool

BeforeSave() public méthode

public BeforeSave ( dynamic item ) : bool
item dynamic
Résultat bool

BuildCommands() public méthode

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
Résultat List

CreateDeleteCommand() public méthode

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
Résultat DbCommand

CreateFrom() public méthode

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

CreateInsertCommand() public méthode

public CreateInsertCommand ( dynamic expando ) : DbCommand
expando dynamic
Résultat DbCommand

CreateUpdateCommand() public méthode

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
Résultat DbCommand

DefaultTo() public méthode

public DefaultTo ( string key, object value, dynamic item ) : void
key string
value object
item dynamic
Résultat void

DefaultValue() public méthode

Gets a default value for the column
public DefaultValue ( dynamic column ) : dynamic
column dynamic
Résultat dynamic

Delete() public méthode

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
Résultat int

Deleted() public méthode

public Deleted ( dynamic item ) : void
item dynamic
Résultat void

DynamicModel() public méthode

public DynamicModel ( ConnectionStringSettings connectionStringSettings, string tableName = "", string primaryKeyField = "" ) : System
connectionStringSettings ConnectionStringSettings
tableName string
primaryKeyField string
Résultat System

DynamicModel() public méthode

public DynamicModel ( string connectionStringName, string tableName = "", string primaryKeyField = "", string descriptorField = "" ) : System
connectionStringName string
tableName string
primaryKeyField string
descriptorField string
Résultat System

Execute() public méthode

public Execute ( DbCommand command ) : int
command DbCommand
Résultat int

Execute() public méthode

Executes a series of DBCommands in a transaction
public Execute ( IEnumerable commands ) : int
commands IEnumerable
Résultat int

Execute() public méthode

public Execute ( string sql ) : int
sql string
Résultat int

GetPrimaryKey() public méthode

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
Résultat object

HasPrimaryKey() public méthode

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
Résultat bool

Insert() public méthode

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
Résultat dynamic

Inserted() public méthode

public Inserted ( dynamic item ) : void
item dynamic
Résultat void

IsValid() public méthode

public IsValid ( dynamic item ) : bool
item dynamic
Résultat bool

ItemAsDictionary() public méthode

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

ItemContainsKey() public méthode

public ItemContainsKey ( string key, ExpandoObject item ) : bool
key string
item ExpandoObject
Résultat bool

KeyValues() public méthode

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

Open() public static méthode

public static Open ( ConnectionStringSettings connectionStringSettings ) : DynamicModel
connectionStringSettings ConnectionStringSettings
Résultat DynamicModel

Open() public static méthode

public static Open ( string connectionStringName ) : DynamicModel
connectionStringName string
Résultat DynamicModel

OpenConnection() public méthode

Returns and OpenConnection
public OpenConnection ( ) : DbConnection
Résultat DbConnection

Paged() public méthode

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
Résultat dynamic

Paged() public méthode

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
Résultat dynamic

Query() public méthode

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

Query() public méthode

public Query ( string sql, DbConnection connection ) : IEnumerable
sql string
connection DbConnection
Résultat IEnumerable

Save() public méthode

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
Résultat int

Scalar() public méthode

Returns a single result
public Scalar ( string sql ) : object
sql string
Résultat object

Single() public méthode

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

Single() public méthode

Returns a single row from the database
public Single ( string where ) : dynamic
where string
Résultat dynamic

TryInvokeMember() public méthode

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

Update() public méthode

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
Résultat int

Updated() public méthode

public Updated ( dynamic item ) : void
item dynamic
Résultat void

Validate() public méthode

public Validate ( dynamic item ) : void
item dynamic
Résultat void

ValidateIsCurrency() public méthode

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

ValidatesNumericalityOf() public méthode

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

ValidatesPresenceOf() public méthode

public ValidatesPresenceOf ( object value, string message = "Required" ) : void
value object
message string
Résultat void

Property Details

Errors public_oe property

public IList Errors
Résultat IList