How to change the value of associated field

后端 未结 3 1511
死守一世寂寞
死守一世寂寞 2021-01-05 15:59

I have 2 classes with a LINQ association between them i.e.:

Table1:       Table2:
ID            ID
Name          Description
              ForiegnID
<         


        
3条回答
  •  醉梦人生
    2021-01-05 17:02

    Table1:       Table2:
    ID            ID
    Name          Description
                  ForeignID
    

    With this :

    Table2.ForeignID = 2

    you receive an error..........

    Example :

    You can change ForeignID field in Table 2 whit this :

       Table2 table = dataContext.Table2.single(d => d.ID == Id)
    
       table.Table1 = dataContext.Table1.single(d => d.ID == newId);
    

    Where the variable newId is the id of the record in Table 2 that would you like associate whit the record in Table 1

提交回复
热议问题