Class EfCodeFirstBusinessBase<TEntity,TContext>

Light weight Entity Framework Code First Business object base class that acts as a logic container for an entity DbContext instance.

Subclasses of this business object should be used to implement most data related logic that deals with creating, updating, removing and querying of data use EF Code First.

The business object provides base CRUD methods like Load, NewEntity, Remove that act on the specified entity type. 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).

These business objects should be used as atomically as possible and call Save() as often as possible to update pending data.

System.Object
  Westwind.Data.EfCodeFirst.EfCodeFirstBusinessBase<TEntity,TContext>
public class EfCodeFirstBusinessBase<TEntity,TContext> : object, IDisposable,
   IBusinessObject<TContext>

Class Members

MemberDescription

Constructor

Base constructor using default behavior loading context by connectionstring name that matches the context

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,     EntityState entityState)

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)

CreateTransactionScope

Allows you to configure how the transaction scope is created internally. Sets the default isolation level to repetable read

public virtual TransactionScope CreateTransactionScope(IsolationLevel isolationLevel)

Delete

Deletes an entity from the main entity set based on a key value.

public virtual bool Delete(object id,     bool saveChanges,     bool useTransaction)

public virtual bool Delete(TEntity entity,     DbSet dbSet,     bool saveChanges,     bool useTransaction)

Dispose

public sealed void Dispose()

Execute

Allows execution of a SQL command as s tring agains the Context's provider and return the result as an Entity collection

public IEnumerable Execute(string sql,     Object[] parameters)

ExecuteNonQuery

Allows execution of an arbitrary non query SQL command against the database.

public int ExecuteNonQuery(string sql,     Object[] parameters)

GetProperty

Retrieves a value from the Properties collection safely. If the value doesn't exist null is returned.

public object GetProperty(string key)

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()

public virtual TEntity NewEntity(TEntity entity)

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 virtual bool Save(TEntity entity,     bool useTransactionScope)

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. Validates both EF entity validation rules on pending changes as well as any custom validation rules you implement in the OnValidate() method.

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 or validation errors. This

Requirements

Namespace: Westwind.Data.EfCodeFirst
Assembly: westwind.data.dll

© West Wind Technologies, 1996-2016 • Updated: 12/12/15
Comment or report problem with topic