public async Task <CMR> GetAsync(int id) { using (var context = new IkarContext()) { var cmr = await context.CMRs .SingleOrDefaultAsync(s => s.CMRId == id); // Pobieranie wskazanej kolekcji await context.Entry(cmr).Collection(p => p.WarehouseDocuments).LoadAsync(); await context.Entry(cmr).Reference(p => p.ArrivalAddress).LoadAsync(); await context.Entry(cmr).Reference(p => p.DeliveryAddress).LoadAsync(); // Pobranie wskaznej właściwości await context.Entry(cmr).Reference(p => p.Truck).LoadAsync(); // Zachłanne pobieranie //var cmr = await context.CMRs // .Include(p=>p.Truck) // .Include(p=>p.Driver) // .Include(p=>p.WarehouseDocuments.Select(x=>x.Vehicle)) // .SingleOrDefaultAsync(s => s.CMRId == id); return(cmr); } }
public async Task UpdateAsync(Driver driver) { using (var context = new IkarContext()) { // context.Drivers.Attach(driver); context.Entry(driver).State = EntityState.Modified; System.Diagnostics.Debug.WriteLine(context.Entry(driver).State); await context.SaveChangesAsync(); } }
public async Task AddAsync(Driver driver) { using (var context = new IkarContext()) { context.Drivers.Add(driver); System.Diagnostics.Debug.WriteLine(context.Entry(driver).State); await context.SaveChangesAsync(); } }