I have a radgrid that calls NeedsDataSource.
I have a method like this:
Which in turn calls this bll bit of code... GetComponents
Now the question:
I know I can't wrap this in a USING because the context will be disposed and the RadGrid does not like this...
How do I dispose of the context when I am done with it correctly?
I have used .toList() in the past but from what i have read this method does not leverage the full power of the radgrids queryable functionality.. Am i wrong in this or what?
I have a method like this:
protected void RadGridParentComponents_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { var result = new Inventory().GetComponets(this.HiddenFieldTag.Value); RadGridParentComponents.DataSource = result; }Which in turn calls this bll bit of code... GetComponents
public IQueryable<TagInformationComponentView> GetComponets(string tag) { using (var dbContext = new TIPWebITLibrary.DAL.TIPWebITDataContext()) { if (String.IsNullOrEmpty(tag)) { throw new ArgumentNullException("tag", "Null or Empty is not allowed"); } var parent = dbContext.tblTechInventories.Where(x => x.Tag == tag).FirstOrDefault(); //TODO: Check to ensure it is a parent var result = from c in dbContext.tblTechInventories join p in dbContext.tblTechItems on c.ItemUID equals p.ItemUID join t in dbContext.tblTechItemTypes on p.ItemTypeUID equals t.ItemTypeUID where c.ParentInventoryUID == parent.InventoryUID select new TagInformationComponentView() { InventoryUID = c.InventoryUID, ProductName = p.ItemName, ProductType = t.ItemTypeName, Serial = c.Serial, Tag = c.Tag }; if (result.Count() == 0) return new List<TagInformationComponentView>().AsQueryable(); return result.AsQueryable(); } }Now the question:
I know I can't wrap this in a USING because the context will be disposed and the RadGrid does not like this...
How do I dispose of the context when I am done with it correctly?
I have used .toList() in the past but from what i have read this method does not leverage the full power of the radgrids queryable functionality.. Am i wrong in this or what?