Entity Framework and calling context.dispose()
When should one call DbContext.dispose() with entity framework? Is this imaginary method bad? public static string GetName(string userId) { var context = new DomainDbContext(); var userName = context.UserNameItems.FirstOrDefault(x => x.UserId == userId); context.Dispose(); return userName; } Is this better? public static string GetName(string userId) { string userName; using(var context = new DomainDbContext()) { userName = context.UserNameItems.FirstOrDefault(x => x.UserId == userId); context.Dispose(); } return userName; } Is this even better, that is, should one NOT call context.Dispose()