moving entity from one data context to another.
-
I've just recently started working with Linq to Sql and was wondering what is the recommendation and process for moving a data entity object from one instance of a data context to another. For example: I have a "Child" data entity. I have created a data context and ran the Child.SingleOrDefault() to determine the record is in the database. So now I want to add this entity to an alternate data context that has already filled a "Parent" entity. I want the "Child" to be added to the "Children" collection of entities of a specific parent. Currently, it looks like I would need to run some sort of linq query against the database to add this "Child" entity to the "Parent". But as I already have all the Child information in the other object, this would be an unnecessary hit against the database. So I have two questions: 1) Is it a recommended practice to move entities between data contexts. 2) How would this be accomplished? Sorry if this isn't clear. Let me know if I need to specify any further details. Thanks.
-
I've just recently started working with Linq to Sql and was wondering what is the recommendation and process for moving a data entity object from one instance of a data context to another. For example: I have a "Child" data entity. I have created a data context and ran the Child.SingleOrDefault() to determine the record is in the database. So now I want to add this entity to an alternate data context that has already filled a "Parent" entity. I want the "Child" to be added to the "Children" collection of entities of a specific parent. Currently, it looks like I would need to run some sort of linq query against the database to add this "Child" entity to the "Parent". But as I already have all the Child information in the other object, this would be an unnecessary hit against the database. So I have two questions: 1) Is it a recommended practice to move entities between data contexts. 2) How would this be accomplished? Sorry if this isn't clear. Let me know if I need to specify any further details. Thanks.