Highway Framework  Release 1.0.1.0
The fastest and smoothest way to great architecture
 All Classes Namespaces Functions Variables Properties Events
Public Member Functions | Protected Member Functions | Properties | Events
Highway.Data.DataContext Class Reference

A base implementation of the Code First Data DataContext for Entity Framework More...

Inheritance diagram for Highway.Data.DataContext:
Highway.Data.Interfaces.IObservableDataContext Highway.Data.Interfaces.IDataContext

List of all members.

Public Member Functions

 DataContext (string connectionString, IMappingConfiguration mapping, IContextConfiguration contextConfiguration=null, ILog log=null)
 Constructs a context
IQueryable< T > AsQueryable< T > ()
 This gives a mockable wrapper around the normal DbSet{T} method that allows for testablity
Add< T > (T item)
 Adds the provided instance of T to the data context
Remove< T > (T item)
 Removes the provided instance of T from the data context
Update< T > (T item)
 Updates the provided instance of T in the data context
Attach< T > (T item)
 Attaches the provided instance of T to the data context
Detach< T > (T item)
 Detaches the provided instance of T from the data context
Reload< T > (T item)
 Reloads the provided instance of T from the database
int Commit ()
 Commits all currently tracked entity changes
IEnumerable< T > ExecuteSqlQuery< T > (string sql, params DbParameter[] dbParams)
 Executes a SQL command and tries to map the returned datasets into an IEnumerable{T} The results should have the same column names as the Entity Type has properties
int ExecuteSqlCommand (string sql, params DbParameter[] dbParams)
 Executes a SQL command and returns the standard int return from the query
int ExecuteFunction (string procedureName, params ObjectParameter[] dbParams)
 

Protected Member Functions

override void OnModelCreating (DbModelBuilder modelBuilder)
 This method is called when the model for a derived context has been initialized, but before the model has been locked down and used to initialize the context. The default implementation of this method takes the IMappingConfiguration array passed in on construction and applies them. If no configuration mappings were passed it it does nothing.

Properties

IEventManager EventManager [get, set]
 The reference to EventManager that allows for ordered event handling and registration

Events

EventHandler< PreSaveEventArgsPreSave
 The event fired just before the commit of the ORM
EventHandler< PostSaveEventArgsPostSave
 The event fired just after the commit of the ORM
- Events inherited from Highway.Data.Interfaces.IObservableDataContext

Detailed Description

A base implementation of the Code First Data DataContext for Entity Framework


Constructor & Destructor Documentation

Highway.Data.DataContext.DataContext ( string  connectionString,
IMappingConfiguration  mapping,
IContextConfiguration  contextConfiguration = null,
ILog  log = null 
)
inline

Constructs a context

Parameters:
connectionStringThe standard SQL connection string for the Database
mappingThe Mapping Configuration that will determine how the tables and objects interact
contextConfigurationThe context specific configuration that will change context level behavior ( Optional )
logThe logger being supplied for this context ( Optional )

Member Function Documentation

T Highway.Data.DataContext.Add< T > ( item)
inline

Adds the provided instance of T to the data context

Template Parameters:
TThe Entity Type being added
Parameters:
itemThe T you want to add
Returns:
The T you added

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
IQueryable<T> Highway.Data.DataContext.AsQueryable< T > ( )
inline

This gives a mockable wrapper around the normal DbSet{T} method that allows for testablity

Template Parameters:
TThe Entity being queried
Returns:
IQueryable{T}

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
T Highway.Data.DataContext.Attach< T > ( item)
inline

Attaches the provided instance of T to the data context

Template Parameters:
TThe Entity Type being attached
Parameters:
itemThe T you want to attach
Returns:
The T you attached

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
int Highway.Data.DataContext.Commit ( )
inline

Commits all currently tracked entity changes

Returns:
the number of rows affected

Implements Highway.Data.Interfaces.IDataContext.

T Highway.Data.DataContext.Detach< T > ( item)
inline

Detaches the provided instance of T from the data context

Template Parameters:
TThe Entity Type being detached
Parameters:
itemThe T you want to detach
Returns:
The T you detached

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
int Highway.Data.DataContext.ExecuteFunction ( string  procedureName,
params ObjectParameter[]  dbParams 
)
inline

Parameters:
procedureName
dbParams
Returns:

Implements Highway.Data.Interfaces.IDataContext.

int Highway.Data.DataContext.ExecuteSqlCommand ( string  sql,
params DbParameter[]  dbParams 
)
inline

Executes a SQL command and returns the standard int return from the query

Parameters:
sqlThe Sql Statement
dbParamsA List of Database Parameters for the Query
Returns:
The rows affected

Implements Highway.Data.Interfaces.IDataContext.

IEnumerable<T> Highway.Data.DataContext.ExecuteSqlQuery< T > ( string  sql,
params DbParameter[]  dbParams 
)
inline

Executes a SQL command and tries to map the returned datasets into an IEnumerable{T} The results should have the same column names as the Entity Type has properties

Template Parameters:
TThe Entity Type that the return should be mapped to
Parameters:
sqlThe Sql Statement
dbParamsA List of Database Parameters for the Query
Returns:
An IEnumerable{T} from the query return

Implements Highway.Data.Interfaces.IDataContext.

override void Highway.Data.DataContext.OnModelCreating ( DbModelBuilder  modelBuilder)
inlineprotected

This method is called when the model for a derived context has been initialized, but before the model has been locked down and used to initialize the context. The default implementation of this method takes the IMappingConfiguration array passed in on construction and applies them. If no configuration mappings were passed it it does nothing.

Typically, this method is called only once when the first instance of a derived context is created. The model for that context is then cached and is for all further instances of the context in the app domain. This caching can be disabled by setting the ModelCaching property on the given ModelBuidler, but note that this can seriously degrade performance. More control over caching is provided through use of the DbModelBuilder and DbContextFactory classes directly.

Parameters:
modelBuilderThe builder that defines the model for the context being created.
T Highway.Data.DataContext.Reload< T > ( item)
inline

Reloads the provided instance of T from the database

Template Parameters:
TThe Entity Type being reloaded
Parameters:
itemThe T you want to reload
Returns:
The T you reloaded

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
T Highway.Data.DataContext.Remove< T > ( item)
inline

Removes the provided instance of T from the data context

Template Parameters:
TThe Entity Type being removed
Parameters:
itemThe T you want to remove
Returns:
The T you removed

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 
T Highway.Data.DataContext.Update< T > ( item)
inline

Updates the provided instance of T in the data context

Template Parameters:
TThe Entity Type being updated
Parameters:
itemThe T you want to update
Returns:
The T you updated

Implements Highway.Data.Interfaces.IDataContext.

Type Constraints
T :class 

Property Documentation

IEventManager Highway.Data.DataContext.EventManager
getset

The reference to EventManager that allows for ordered event handling and registration

Implements Highway.Data.Interfaces.IDataContext.


Event Documentation

EventHandler<PostSaveEventArgs> Highway.Data.DataContext.PostSave

The event fired just after the commit of the ORM

Implements Highway.Data.Interfaces.IObservableDataContext.

EventHandler<PreSaveEventArgs> Highway.Data.DataContext.PreSave

The event fired just before the commit of the ORM

Implements Highway.Data.Interfaces.IObservableDataContext.


The documentation for this class was generated from the following file: