Home » SQL Server

Reference child field from parent in update

I am new to L2S and I want to update some fields in a table.

I have a parent DispositionHold table which has a PK of DispositionHoldID and a child table, Disposition with a PK DispositionID and FK DispositionHoldID.

I want to reference the child PK DispositionID in a where clause and I want to update the parent DispositionHold table.

One query I tried:


var updateHold =
        (from dispositionHold in db.DispositionHolds
         where dispositionHold.Dispositions.DispositionID == dispositionID
         select dispositionHold).SingleOrDefault();

 I can't do this because I can't get to dispositionHold.Dispositions.DispositionID. I can only get to dispositionHold.Dispositions and then I get a list of extension methods. How can I reference the PK of the child table?





1 Answer Found


Answer 1

Ok so I tried this query which looks like it will work. I just reversed the query to come from the child table to the parent instead of the other way around.


var updateHold =
        (from disposition in db.Dispositions
         where disposition.DispositionID == dispositionID
         select disposition.DispositionHold).SingleOrDefault();




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure