by thebeebs
11. November 2008 02:28
Someone asked me the other day why I returned inside a using like this:
using (SiteEntities context = new SiteEntities(Environment.GetConnectionString("SiteEntities"))) { HelpItems originalItem = (from h in context.HelpItems where h.Id== Item.Id select h).FirstOrDefault(); originalItem.ModifiedBy = item.ModifiedBy; return context.SaveChanges(); }
Their comment was, well your not closing the using so the Context won't dispose.
This is wrong... Even though we return, the context does dispose, this is the way the using works and one of the reasons it's so useful.
9a2f2095-dae2-4a4d-acff-59a9ceca1bc9|0|.0
Tags: