Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. moving entity from one data context to another.

moving entity from one data context to another.

Scheduled Pinned Locked Moved LINQ
databasequestioncsharplinqtutorial
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stryder_1
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • S Stryder_1

      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.

      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      Hi! You can not move an entry between tables. You have to copy all properties by hand. Sorry.

      Andreas Johansson
      IT Professional at Office IT Partner i Norrbotten Sweden
      What we don't know. We learn.
      What you don't know. We teach

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups