none
Delete query in LinqToSQL to delete child records based on ParentObjectId within one table . RRS feed

  • Question

  • Delete query in LinqToSQL to delete child records based on ParentObjectId within one table .
    • Moved by Mog Liang Monday, May 3, 2010 5:32 AM (From:Windows Communication Foundation)
    Thursday, April 29, 2010 12:48 PM

Answers

  • PolicyMenuObjects.DeleteAllOnSubmit( PolicyMenuObjects.Where( p => p.ParentPolicyMenuObjectId == ID ) );
    ParentPolicyMenuObjects.DeleteAllOnSubmit( ParentPolicyMenuObjects.Where( p => p.ParentPolicyMenuObjectId == ID ) );
    SubmitChanges();
    Wednesday, May 12, 2010 6:32 PM

All replies

  • Hi,

    Could you please provide us with more detailed information about your scenario?  

    Thanks
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 6, 2010 1:05 PM
    Moderator
  • I have table

    SELECT

     

    TOP 1000 [PolicyMenuObjectId]

     

    ,[PolicyMenuObjectName]

     

    ,[PolicyMenuObjectDisplayName]

     

    ,[PolicyMenuObjectType]

     

    ,[Level]

     

    ,[ParentPolicyMenuObjectId]  // This is reference to PolicyMenuObjectId

     

    ,[IsActive]

     

    ,[URL]

     

    ,[ImageURL]

     

    ,[CreatedBy]

     

    ,[CreatedDate]

     

    ,[ModifiedBy]

     

    ,[ModifiedDate]

     

    FROM [Policy].[dbo].[PolicyMenuObject]

    in this table at the time of deleting one record, i have to check if it is ParentPolicyMenuObjectId for other that also i want to delete.

     

     

    Wednesday, May 12, 2010 10:41 AM
  • PolicyMenuObjects.DeleteAllOnSubmit( PolicyMenuObjects.Where( p => p.ParentPolicyMenuObjectId == ID ) );
    ParentPolicyMenuObjects.DeleteAllOnSubmit( ParentPolicyMenuObjects.Where( p => p.ParentPolicyMenuObjectId == ID ) );
    SubmitChanges();
    Wednesday, May 12, 2010 6:32 PM