Hi All,
I am using Adapter/VS2005/C#
I have three tables A, B and C.
A is related to B (1:m) and C is related to B (1:m).
A -< B >- C
Now if i wanted to delete an row in A and hence delete all relationships in table B. But only delete the related row in C if only it does not have a FK relationship with another row.
I thought of using GetDependingRelatedEntities/GetDependentRelatedEntities methods but neither of these return anything (I am using Prefetch to get all data first).
BrochureItemEntity b = (BrochureItemEntity)dataGridView1.CurrentRow.DataBoundItem;
if (b != null)
{
using (DataAccessAdapter da = new DataAccessAdapter())
{
IPrefetchPath2 ppath = new PrefetchPath2((int)EntityType.BrochureItemEntity);
IPrefetchPathElement2 path = ppath.Add(BrochureItemEntity.PrefetchPathBrochureItemContentText);
path.SubPath.Add(BrochureItemContentTextEntity.PrefetchPathContentText);
da.KeepConnectionOpen = true;
da.FetchEntity(b, ppath);
UnitOfWork2 work = new UnitOfWork2();
if (b.BrochureItemContentText != null)
{
if (b.BrochureItemContentText != null)
{
foreach(BrochureItemContentTextEntity c in b.BrochureItemContentText)
{
if (c.ContentText != null)
{
[colorvalue="FF0000"]// -- this is where I need to determine if the item has other relationships. if not then add to uow for deletion.[/color]
}
}
work.AddCollectionForDelete(b.BrochureItemContentText);
}
}
work.AddForDelete(b);
work.Commit(da, true);
}
}
Thanks