Last post Nov 03, 2016 11:51 AM by Mikesdotnetting
Nov 03, 2016 09:09 AM|sudip_inn|LINK
just read this
but it is not clear what is difference between attach and AddObject function. both looks same to me.
please tell me the difference between attach and AddObject with example. when to use which one?
Nov 03, 2016 09:51 AM|Mikesdotnetting|LINK
ObjectContext.AddObject and ObjectContext.Attach are deprecated. You should use the DbContext API instead. The equivalent methods are Add and Attach. When you use the Add method, the entity starts being tracked by the context with an EntityState of "Added".
When you use Attach, the context starts tracking it with an EntityState of "Unchanged".
You use the Add method for new objects, and the Attach method for existing objects.
Nov 03, 2016 10:29 AM|sudip_inn|LINK
any difference between attach and AddObject exist or both are same ?
Nov 03, 2016 11:51 AM|Mikesdotnetting|LINK
The difference between them is the same as the difference between DbContext.Attach and DbContext.Add, which I detailed above.