//private LocationsContext dbCtx; //public LocationsContext DbCtx //{ // get // { // if (dbCtx == null) // { // dbCtx = new LocationsContext(); // } // return dbCtx; // } //} public static void WriteLocation(Location loc) { using (var db = new LocationsContext()) { db.Locations.Add(loc); db.SaveChanges(); } }
public static Location ReadLocation(string city) { using (var db = new LocationsContext()) { db.Database.EnsureCreated(); var query = from l in db.Locations where l.City.ToLower() == city.ToLower() select l; if (query?.ToList().Count != 0) { return(query.ToList()[0]); } else { return(null); } } }