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