Database Reference
In-Depth Information
public class Order
{
public Order()
{
Items = new HashSet<OrderItem>();
}
public int OrderId { get; set; }
public int CustomerId { get; set; }
public virtual Customer Customer { get; set; }
public string OrderNo { get; set; }
public virtual ICollection<OrderItem> Items { get; set; }
}
public class OrderItem
{
public int OrderId { get; set; }
public virtual Order Order { get; set; }
public int OrderItemId { get; set; }
public Double Qty { get; set; }
public Decimal Price { get; set; }
}
Connections and Transactions
Every major ORM framework supports two design patterns, such as a Repository Pattern and Unit of Work Pattern.
A Repository Pattern abstracts data from business entities, making it agnostic to the data source. The business
layer does not know the location of the data nor the type of the data storage. For example, data can live in the database
or be provided by a set of web services. A Repository Pattern establishes a mapping between the business entities and
the underlying data structures, and it transforms requests from the applications to data access methods, for example,
database queries or web service method calls.
Note
You can read more about repository patterns at: http://msdn.microsoft.com/en-us/library/ff649690.aspx .
A Unit of Work Pattern is responsible for tracking all of the changes in business objects and saving them into the
data sources. It performs transaction management on the data side, handles concurrency issues, and is responsible
for all aspects of data modifications in the system.
The functionality of the both patterns is implemented in the DbContext class of Entity Framework, which
manages the entity objects during run time. Applications need to inherit the class from DbContext and initialize
the data mapping required for the Repository Pattern. Every time changes need to be applied to the database,
applications should call the SaveChanges() method of DbContext class.
You can read more about the DbContext class, including its lifetime considerations, at:
http://msdn.microsoft.com/en-us/data/jj729737.aspx .
Note
 
 
Search WWH ::




Custom Search