Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbContext.Entry attaching Entity

From my research, I read that calling DbContext.Entry(someEntity) would automatically attached the entity to the context.

However, when I do this I find that the entity's state is detached.

Can anyone shed some light on this and how the DbContect.Entry works. I'm using EF 5.0

Thanks.

like image 686
Chris Avatar asked Oct 11 '12 03:10

Chris


1 Answers

If you're wanting to attach an object, what you actually want is DbSet.Attach. DbContext.Entry is only giving you information about the entity, and allows you to change the state if it's already been attached.

Here's a good post about entity states from MSDN

like image 167
Mark Oreta Avatar answered Oct 14 '22 16:10

Mark Oreta