Clear All Childs With 1 Query

2 posts, 0 answers
  1. amir sherafatian
    amir sherafatian avatar
    42 posts
    Member since:
    Aug 2009

    Posted 24 Sep 2009 Link to this post

    hi
    i have two class ( DCDocumentAdmin and DCGroup ) that i declare a collection field of type DCDocumentAdmiin in DCGroup for make a 1-to-many relation between those , with this , i have a GroupId field in database that is coantain the Related group id for DCDocumentAdmin ,
    now i try to remove the DCDocumentAdmins that have a special GroupId ,
    i do this by removing DCDocumentAdmins one by one in separate queries , ( i write my code for you in below ) :
    (market function as Bold Remove DocumentAdmins One By One with separate queris that this have no good way)

    public DCDocumentAdmin RetrieveDCDocumentAdminById(int DocumentAdminId)
                {
                    try
                    {
                        var query = (from q in scope.Extent<DCDocumentAdmin>()
                                 where q.Id == DocumentAdminId
                                 select q).Single();
                        return query;
                    }
                    catch (Exception ex)
                    {
                       
                        throw;
                    }
                }

    public void RemoveDCDocumentAdminById(int DocumentAdminId)
                {
                    try
                    {
                        DCDocumentAdmin DocumentAdmin = RetrieveDCDocumentAdminById(DocumentAdminId);
                        scope.Transaction.Begin();
                        scope.Remove(DocumentAdmin);
                        scope.Transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                       
                        throw;
                    }
                }

    public void RemoveDCGruopDocumentAdminsByArchiveId(int archiveId)
                {
                    DCGroup archive = RetrieveDCGroupById(archiveId);

                    for (int i = 0; i < archive.DocumentAdmins.Count; i++)
                    {
                        documentAdminManager.RemoveDCDocumentAdminById(archive.DocumentAdmins[i].Id);
                    }
                }


    HOW CAN I REMOVE THE DCDocumentAdmins THAT HAVE A SPECIAL GroupID in one query like below (the way that i do before) :
    ( delete from DCDocumentAdmin where DCDocumentAdmin.GroupId  = @GroupId )

    in the way that i use to make relation between tables in openaccess i have no access to GroupId when i working with DCDocumentAdmin to remove admins in 1 query

    what is my solution
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 24 Sep 2009 Link to this post

    Hello amir sherafatian,

    We provided an answer to the question in your forum thread ID: 245005.

    Best wishes,
    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top