2

I am using EntityFramework v6.1.2.

I read some articles and know about AsNoTracking extension.

When AsNoTracking is called, it means that if the entity is not attached, the context and the entity updated "should fail".

But I have tried and updated successfully, my code is in below:

private readonly DemoObjectContext _objectContext = new DemoObjectContext();
var order = _objectContext.Orders.AsNoTracking().FirstOrDefault(x => x.Id == 1);(1 is the primary key)

order.OrderStatus = OrderStatus.Processing; // change the orderstatus
                //_objectContext.Set<Order>().Attach(order);
                _objectContext.Entry(order).State = EntityState.Modified;
                _objectContext.SaveChanges();

Is something wrong or did EntityFramework(6.1.2) changed something?

Please help me

Charuක
  • 12,953
  • 5
  • 50
  • 88
Allen
  • 82
  • 1
  • 8

1 Answers1

1

No issues with EF. It works because Entry attaches the entity to the context.

See here for more details.

And on this SO specifically about Entry

Community
  • 1
  • 1
Klinger
  • 4,900
  • 1
  • 30
  • 35