I using extension for Object, because it provides very short accessible string.
public static BusinessLayer.Models.SearchEngineEntities db(this object o)
{
if (HttpContext.Current == null)
return new BusinessLayer.Models.SearchEngineEntities(ConfigurationManager.ConnectionStrings["SearchEngineEntities"].ConnectionString);
if (HttpContext.Current.Items.Contains("DataContext"))
{
return (BusinessLayer.Models.SearchEngineEntities)HttpContext.Current.Items["DataContext"];
}
BusinessLayer.Models.SearchEngineEntities context = new BusinessLayer.Models.SearchEngineEntities(ConfigurationManager.ConnectionStrings["SearchEngineEntities"].ConnectionString);
HttpContext.Current.Items.Add("DataContext", context);
return context;
}
So in a result I have execution string like:
"".db().Users.Include("")....
But I'm not 100% sure that is best solution. I hope you know better than me, where and how to store DataContext or ObjectContext instance. Maybe you know better solution...
Thank you in advice.