Exemplo n.º 1
0
        public async Task Add(Vehicle vehicle)
        {
            // LogState(vehicle);

            // context.Attach(vehicle);

            // Strategia
            context.ChangeTracker.TrackGraph(vehicle, e =>
            {
                if (e.Entry.IsKeySet)
                {
                    e.Entry.State = EntityState.Unchanged;
                }
                else
                {
                    e.Entry.State = EntityState.Added;
                }
            });

            await context.Vehicles.AddAsync(vehicle);

            //var entities = context.ChangeTracker.Entries().ToList();

            var entities2 = context.ChangeTracker.Entries().ToList();

            LogState(vehicle);

            await context.SaveChangesAsync();

            LogState(vehicle);
        }
Exemplo n.º 2
0
        public async Task Add(Soldier entity)
        {
            await context.AddAsync(entity);

            await context.SaveChangesAsync();
        }