Copy of record in a table (with copies to FKs) RRS feed

  • Question

  • Hi there,


    I need to clone records in my MSSQL  database. But the problem is I need to clone also all records which are forein keys in my source records (and for them do the same as well). I have many tables to clone records within so my question is - is is possible to do this process using LINQ automatically? Or for example detect, which integer field in table_A is a forein key so I can navigate to these forein table - this would do the trick I think. 


    Example: let's say I want to clone record from table A which has FK to table B


    table_a records: [id=1,value1=abc,value2=555,id_tableb=1]

    table_b records: [id=1,value=123]


    after cloning records:



    table_a records:


    [id=2,value1=abc,value2=555,id_table_b=2] (cloned master record)

    table_b records:


    [id=2,value=123] (cloned FK record)


    Wednesday, March 30, 2011 8:35 AM