DbContext.Entry附加实体 [英] DbContext.Entry attaching Entity
问题描述
然而,当我这样做时,我发现实体的状态是分离的。
任何人都可以看出这一点,以及DbContect.Entry如何工作。我使用EF 5.0
谢谢。
如果你想要附加一个对象,你实际想要的是 DbSet.Attach 。 DbContext.Entry只提供有关实体的信息,并允许您更改状态(如果已经附加)。
这是一个关于MSDN的实体状态的好消息
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.
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
这篇关于DbContext.Entry附加实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!