Alurfepiflern
New Member
I have a db as below:
I am using EF and trying to get the object. Under normal circumstances after selecting PRODUCT Entity from database I can reach ACCESSLEVEL Entity of PRODUCT Entity like below:In selecting, I use INCLUDE (NOTE: the code below works fine!)\[code\]//In a method located in some BL layerpublic ProductCollection Load(){ ProductCollection Result = new ProductCollection(); //Derived from Listusing (var Context = base.Entities) { collection = from ItemProduct in Context.Product .Include("AccessLevel"); return Result.AddRange(collection); }}//In page load in aspx.cs fileforeach(var product in BL.Load()){ Response.Write(product.AccessLevel.Name);}\[/code\]However, in here when I do the thing below it does NOT work!\[code\]//In a method located in some BL layer public ProductCollection Load() { ProductCollection Result = new ProductCollection(); //Derived from List using (var Context = base.Entities) { collection = from ItemProduct in Context.Product .Include("AccessLevel") .Join(Context.Product_Category_Map.Where(c => c.ProductCategoryId == 3), product => product, map => map.Product, (product, map) => product ));; return Result.AddRange(collection); } } //In page load in aspx.cs file foreach(var product in BL.Load()) {//I Get Exception here and cannot react the included object Response.Write(product.AccessLevel.Name); }\[/code\]The Exception is:\[quote\] The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.\[/quote\]What I finally want is to get products by the given ProductCategory Id.How can I do that?Thanks in advance.