I have recovered a project in ASP.NET MVC 5 uses a SQL database SERVER 2016 and Entity Framwork 6. In this code we will create a new instance of the DataContext whenever he wants to use an entity. Which is not optimal ... please tell me what you should not do. And that you proposed as correction ?See why sometimes we use Single (), sometimes SingleOrDefault ()?    public class PersonalInfoDbMgr : BaseDbMgr    {        public static PersonalInfo GetByUserIdfromDb(string userId)        {            var db = NewContextDb;            return db.PersonalInfos.SingleOrDefault(i => i.AspNetUser.Id == userId);        }        public static PersonalInfo GetFromEmail(string email)        {            var db = NewContextDb;            return db.PersonalInfos.Where(m => m.Email.ToLower() == email.ToLower()).SingleOrDefault();        }        public static PersonalInfo GetFromAspNetUserId(string userId)        {            var db = NewContextDb;            return db.PersonalInfos.Where(m => m.IdUser == userId).Single();        }    }public class BaseDbMgr    {        public static LocalDbEntities NewContextDb        {            get            {                return new LocalDbEntities();            }        }        protected static int SaveChanges(LocalDbEntities db)        {            return db.SaveChanges();        }    }
Best practice for handling DbContext (Entity Framework)
c#;linq;entity framework;asp.net mvc;linq to sql