The business object provides base CRUD methods like Load, NewEntity, Remove. The Save() method uses the EF specific context based SaveChanges which saves all pending changes (not just those for the current entity and its relations). As such these business objects should be used as atomically as possible and call Save() as often as possible to change pending data.
public class EfCodeFirstBusinessBase<TEntity,TContext> : object, IDisposable, IBusinessObject<TContext>
| Member | Description | |
|---|---|---|
![]() |
Constructor | Base constructor using default behavior. Loads a new DbContext |
![]() |
AbortChanges | Cancel Changes on the current connected context public virtual void AbortChanges();
|
![]() |
Attach | Attaches an untracked to the internal context and marks it as modified optionally Note: child elements need to be manually added. public TEntity Attach(TEntity entity,
bool addNew); public object Attach(object entity,
bool addNew); |
![]() |
CloseConnection | explicitly closes a connection public void CloseConnection();
|
![]() |
CreateParameter | Creates a new SQL Parameter public DbParameter CreateParameter(string name,
object value, ParameterDirection direction, DbType type); public DbParameter CreateParameter(string name,
object value, ParameterDirection direction); |
![]() |
Delete | removes an individual entity instance. public virtual bool Delete(TEntity entity,
DbSet dbSet, bool saveChanges); public bool Delete(object id);
|
![]() |
Dispose | public sealed void Dispose();
|
![]() |
Execute<TResult> | Allows execution of a SQL command as s tring agains the Context's provider and return the result as an Entity collection public IEnumerable<TResult> Execute<TResult>(string sql,
Object[] parameters); |
![]() |
ExecuteNonQuery | Allows execution of an arbitrary non query SQL command against the database. public int ExecuteNonQuery(string sql,
Object[] parameters); |
![]() |
Load | Loads in instance based on its integer id public TEntity Load(int id);
public TEntity Load(Guid id);
public TEntity Load(string id);
|
![]() |
NewEntity | Creates a new instance of an Entity tracked by the DbContext. public virtual TEntity NewEntity();
|
![]() |
OpenConnection | Opens the connection on this business object's Context. Use this before manually creating Transactions to ensure transactions execute on a single connection. public void OpenConnection();
|
![]() |
Save | Saves all changes. public bool Save(TEntity entity);
|
![]() |
SetError | Sets an internal error message. public void SetError(string Message);
public void SetError(Exception ex,
bool checkInnerException); public void SetError();
|
![]() |
ToString | Overridden to display error messages if one exists public virtual string ToString();
|
![]() |
Validate | Validate() is used to validate business rules on the business object. Generally this method consists of a bunch of if statements that validate the data of the business object and adds any errors to the wwBusiness.ValidationErrors collection. public bool Validate(TEntity entity,
bool clearValidationErrors); |
![]() |
AutoValidate | Determines whether or not the Save operation causes automatic validation |
![]() |
Context | |
![]() |
Entity | Internally loaded instance from load and newentity calls |
![]() |
ErrorException | Instance of an exception object that caused the last error |
![]() |
ErrorMessage | Error Message of the last exception |
![]() |
Properties | |
![]() |
ValidationErrors | A collection that can be used to hold errors. This collection is set by the AddValidationError method. |