public static int InsertInSupermarketTable(string supermarketName) { SupermarketReportsEntities db = new SupermarketReportsEntities(); using (db) { var supermarket = new SupermarketMSSql.Model.Supermarket() { Name = supermarketName }; bool doesExist = db.Supermarkets.Any(s => s.Name == supermarket.Name); //bool doesExist = db.Supermarkets.Select(s => s.Name == supermarket.Name).ToList().Count > 0; if (!doesExist) { db.Supermarkets.Add(supermarket); db.SaveChanges(); } return db.Supermarkets .Where(s => s.Name == supermarket.Name) .First() .SupermarketId; } }
public static int InsertInSupermarketTable(string supermarketName) { SupermarketReportsEntities db = new SupermarketReportsEntities(); using (db) { var supermarket = new SupermarketMSSql.Model.Supermarket() { Name = supermarketName }; bool doesExist = db.Supermarkets.Any(s => s.Name == supermarket.Name); //bool doesExist = db.Supermarkets.Select(s => s.Name == supermarket.Name).ToList().Count > 0; if (!doesExist) { db.Supermarkets.Add(supermarket); db.SaveChanges(); } return(db.Supermarkets .Where(s => s.Name == supermarket.Name) .First() .SupermarketId); } }