Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        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();
            }
        }