RE: An entity object cannot be referenced by multiple instances of
- From: v-zhye@xxxxxxxxxxxxxxxxxxxx (Zhi-Xin Ye [MSFT])
- Date: Thu, 27 Nov 2008 13:40:50 GMT
Dear ***,
Why not declaring the ObjectContext object as global variable?
Anyway, if it's neccessary to use local variables, since objects attached
to one ObjectContext cannot be attached to another ObjectContext, you have
to detach them first, to retain the relationship, you can enumerate all
relations via ObjectContext.ObjectStateManager.GetObjectStateEntry(),
temporarily store the graph after the detach. And reconstructing the graph
of objects afterwards when needed. For more information, you can refer to
these documents:
ObjectStateManager..::.GetObjectStateEntry Method (EntityKey)
http://msdn.microsoft.com/en-us/library/bb155228.aspx
How to: Attach Related Objects (Entity Framework)
http://msdn.microsoft.com/en-us/library/bb896245.aspx
If you have any questions or concerns, please feel free to let me know.
Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- References:
- Prev by Date: IDataReader.Read() throws Exception! How can i skip a row?
- Next by Date: RE: An entity object cannot be referenced by multiple instances of
- Previous by thread: RE: An entity object cannot be referenced by multiple instances of
- Next by thread: RE: An entity object cannot be referenced by multiple instances of
- Index(es):