VS 2010, .NET 4.0, C#
Hello All,
I’m currently planning a new web app and intend to use entity framework for the first time. I have read a few articles that say that one ObjectContext instance should be created per HTTP request and I’m trying to find out how this can be implemented. I have seen a few very complex examples but I’m finding them hard to follow. Basically what I want to do is select a product which I will display in a user control, then at a later point in the request lifecycle I will need to get a list of categories, related items etc.
Product selection:
using (acmsEntities oEntities = new acmsEntities())
{
ObjectQuery<acms_Product> oProduct = oEntities.acms_Product;
IQueryable<acms_Product> query = from p in oProduct where p.pro_id == ProductID select p;
EntityProduct = query.FirstOrDefault();
}
Could anyone tell me the best way to implement this (ideally with examples) and also explain the mechanisms involved in maintaining the object context for the life of the request?
Does the entity framework have this functionality built-in or does it require custom objects to persist the object context?
How intensive is the creation of each object context instance and is there a big resource overhead?
Thanks for your help!
Rick
Hello All,
I’m currently planning a new web app and intend to use entity framework for the first time. I have read a few articles that say that one ObjectContext instance should be created per HTTP request and I’m trying to find out how this can be implemented. I have seen a few very complex examples but I’m finding them hard to follow. Basically what I want to do is select a product which I will display in a user control, then at a later point in the request lifecycle I will need to get a list of categories, related items etc.
Product selection:
using (acmsEntities oEntities = new acmsEntities())
{
ObjectQuery<acms_Product> oProduct = oEntities.acms_Product;
IQueryable<acms_Product> query = from p in oProduct where p.pro_id == ProductID select p;
EntityProduct = query.FirstOrDefault();
}
Could anyone tell me the best way to implement this (ideally with examples) and also explain the mechanisms involved in maintaining the object context for the life of the request?
Does the entity framework have this functionality built-in or does it require custom objects to persist the object context?
How intensive is the creation of each object context instance and is there a big resource overhead?
Thanks for your help!
Rick