private void loadPasses() { using (drbEntities db = new drbEntities()) { string q = $"SELECT * FROM `trip`"; Dispatcher.Invoke(new Action(() => { branyCB.ItemsSource = new ObservableCollection <trip>(db.Database.SqlQuery <trip>(q).ToList()); })); } }
public void Execute <T>(List <T> queryList, int nSize = 1000) { var list = new List <List <T> >(); for (int i = 0; i < queryList.Count; i += nSize) { list.Add(queryList.GetRange(i, Math.Min(nSize, queryList.Count - i))); } using (drbEntities db = new drbEntities()) foreach (var queries in list) { db.Database.ExecuteSqlCommandAsync(string.Join("", queries)); } }
private bool insertTrip(trip trip, ref List <string> queriList) { using (drbEntities db = new drbEntities()) { bool carOK = false; bool driverOK = false; bool gateOK = false; string query = ""; string q = ""; lock (db.car) if (db.car.Any(x => x.spz == trip.car1.spz)) { if (db.car.Any(x => x.spz == trip.car1.spz && x.model == trip.car1.model && x.company == trip.car1.company)) { trip.car1 = db.car.First(x => x.spz == trip.car1.spz && x.model == trip.car1.model && x.company == trip.car1.company); carOK = true; } else { return(false); } } else { trip.car1 = db.car.Add(trip.car1); db.SaveChanges(); carOK = true; } lock (db.driver) if (db.driver.Any(x => x.licence == trip.driver1.licence)) { if (db.driver.Any(x => x.licence == trip.driver1.licence && x.name == trip.driver1.name)) { trip.driver1 = db.driver.First(x => x.licence == trip.driver1.licence && x.name == trip.driver1.name); driverOK = true; } else { return(false); } } else { trip.driver1 = db.driver.Add(trip.driver1); db.SaveChanges(); driverOK = true; } lock (db.gate) if (db.gate.Any(x => x.gate_identificator == trip.gate1.gate_identificator)) { if (db.gate.Any(x => x.gate_identificator == trip.gate1.gate_identificator && x.type == trip.gate1.type)) { trip.gate1 = db.gate.First(x => x.gate_identificator == trip.gate1.gate_identificator && x.type == trip.gate1.type); gateOK = true; } else { return(false); } } else { trip.gate1 = db.gate.Add(trip.gate1); db.SaveChanges(); gateOK = true; } lock (db.pass) { trip.pass1 = db.pass.Add(trip.pass1); db.SaveChanges(); } lock (queriList) queriList.Add($"INSERT INTO `trip` ( car, driver, pass, gate, date1, date2) VALUES ({trip.car1.car_id}, {trip.driver1.driver_id}, {trip.pass1.pass_id}, {trip.gate1.gate_id}, {trip.date1}, {trip.date2});"); return(true); } }