This is a migrated thread and some comments may be shown as answers.

Clear All Childs With 1 Query

1 Answer 39 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
amir sherafatian
Top achievements
Rank 1
amir sherafatian asked on 24 Sep 2009, 05:25 AM
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

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 24 Sep 2009, 03:45 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
amir sherafatian
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or