DeleteEntitiesDirectlyCall

Posts   
 
    
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 27-Oct-2008 00:45:19   

Greeting,

i have 3 tables =cashDivident (TransID,....) =GlVoucherHeader (voucherID,TransID,....) =GlVoucherDetail (VoucherID, serialNo,...)

Relation =cashDivident & GlVoucherHeader Virtual relation on(TransID) "no relation in designer" GlVoucherHeader & GlVoucherDetail one to many on VoucherID

Scenario Deleting item from cashDivident and its related records in GlVoucherHeader and GlVoucherDetail

Problem no exception appear but really deleted from cashDivident only

Environment

LLBL 2.5 latest build using adapter VS 2008



foreach (var item in cashDividentEc)
                {
                    var vdDeleteFilter = new RelationPredicateBucket();
                    var joinDetail = new EntityRelation(GLVoucherHeaderFields.VoucherID, GLVoucherDetailFields.VoucherID, RelationType.OneToMany);
                    vdDeleteFilter.Relations.Add(joinDetail);
                    var joinDetail1 = new EntityRelation(FNDCustomerDistributionFields.TransID, GLVoucherHeaderFields.FundTransID, RelationType.OneToMany);
                    vdDeleteFilter.Relations.Add(joinDetail1);
                    vdDeleteFilter.PredicateExpression.Add(FNDCustomerDistributionFields.TransID == item.TransID);

                    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherDetailEntity), vdDeleteFilter);

                    var vhDeleteFilter = new RelationPredicateBucket();
                    var joinHeader = new EntityRelation(FNDCustomerDistributionFields.TransID, GLVoucherHeaderFields.FundTransID, RelationType.OneToMany);
                    vhDeleteFilter.Relations.Add(joinHeader);
                    vhDeleteFilter.PredicateExpression.Add(FNDCustomerDistributionFields.TransID == item.TransID);

                    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);
                    
                    uow.AddForDelete(item);
                }


                using (var adapter=DataAccess.DataAdapterFactory.Create())
                {
                    uow.Commit(adapter, true);
                }


daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Oct-2008 03:33:30   

Hi mohamed, I think this code should be sufficient:

foreach (var item in cashDividentEc)
{
    // delete detail
    var vDetailDeleteFilter = new RelationPredicateBucket(GLVoucherHeaderFields.TransID == item.TransID);
    vdDeleteFilter.Relations.Add(new EntityRelation(GLVoucherHeaderFields.VoucherID, GLVoucherDetailFields.VoucherID, RelationType.OneToMany)); 
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherDetailEntity), vdDeleteFilter);

    //  delete header
    var vHeaderDeleteFilter = new RelationPredicateBucket(GLVoucherHeaderFields.TransID == item.TransID);       
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);
    
    // delete item
    uow.AddForDelete(item);
}

Above should be add the delete actions just fine. However if you are experimenting something wrong, please make a test with just 1 cashDividentEc and paste the generated SQL and the RuntimeLibraries version

Also, at your code you are adding a lot of delete calls. If cashDividentEc.Count is, for example, 100, the code will execute 300 delete calls. Maybe would be more efficient if you:

  1. Get the list of transIds to delete:
List<int> transIds = new List<int>;
foreach (var item in cashDividentEc)
{
   transIds.Add(item.TransId);
}
  1. Use that list to make FieldCompareRangePredicate's.

  2. Pass that filters (step 2) to the delete calls. And add three DeleteEntitiesDirectly calls (one for each type of entity).

David Elizondo | LLBLGen Support Team
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 27-Oct-2008 11:13:25   

Hi daelmo,

thanks daelmo

i just make small change and worked


 // delete header
    var vHeaderDeleteFilter = new RelationPredicateBucket(GLVoucherHeaderFields.TransID == item.TransID);       
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);

To


// delete header  This is Changed
    var vHeaderDeleteFilter = new RelationPredicateBucket(FNDCustomerDistributionFields.TransID == item.TransID);       
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);

but i want to ask about why its work with FNDCustomerDistributionFields.TransID not GLVoucherHeaderFields.TransID Is there something strange !!!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Oct-2008 12:02:06   

but i want to ask about why its work with FNDCustomerDistributionFields.TransID not GLVoucherHeaderFields.TransID Is there something strange

No idea !!

What's the relation between FNDCustomerDistribution entity and GLVoucherHeader entity?

Doesn't GLVoucherHeader entity contain a TransId field?

Are you sure it's writter TransID instead of not TransId with a small 'd' at the end?

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 27-Oct-2008 23:11:02   

What's the relation between FNDCustomerDistribution entity and GLVoucherHeader entity?

elation between FNDCustomerDistribution entity and GLVoucherHeader one to many but not design in database only on run time

Doesn't GLVoucherHeader entity contain a TransId field?

no its contains TransID field

Are you sure it's writter TransID instead of not TransId with a small 'd' at the end?

i'm sure its TransID if else its throw exception in design time

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Oct-2008 10:36:57   

Would you please post the produced SQL Query? Check Troubleshooting and debugging

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 28-Oct-2008 13:28:53   

this with GLVoucherHeaderFields.FundTransID


Executed Sql Query: 
    Query: DELETE FROM [FundMarket].[dbo].[GLVoucherHeader] 
                    FROM ( [FundMarket].[dbo].[FNDCustomerDistribution]  
                        INNER JOIN [FundMarket].[dbo].[GLVoucherHeader]  
                            ON  [FundMarket].[dbo].[FNDCustomerDistribution].[TransID]=[FundMarket].[dbo].[GLVoucherHeader].[FundTransID]) 
                    WHERE ( ( [FundMarket].[dbo].[GLVoucherHeader].[FundTransID] = @FundTransID1))
    Parameter: @FundTransID1 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 09ef6f18-9358-4afe-8473-206a38df303f.


and this with FNDCustomerDistributionFields.TransID


Executed Sql Query: 
    Query: DELETE FROM [FundMarket].[dbo].[GLVoucherHeader] 
                    FROM ( [FundMarket].[dbo].[FNDCustomerDistribution]  
                        INNER JOIN [FundMarket].[dbo].[GLVoucherHeader]  
                            ON  [FundMarket].[dbo].[FNDCustomerDistribution].[TransID]=[FundMarket].[dbo].[GLVoucherHeader].[FundTransID]) 
                    WHERE ( ( [FundMarket].[dbo].[FNDCustomerDistribution].[TransID] = @FundTransID1))
    Parameter: @FundTransID1 : Guid. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 09ef6f18-9358-4afe-8473-206a38df303f.


MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Oct-2008 21:56:00   

Hi

Please could you post the generated SQL in both cases as that may give us a better idea of what is going on.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 29-Oct-2008 09:57:12   

mohamed wrote:

Hi daelmo,

thanks daelmo

i just make small change and worked


 // delete header
    var vHeaderDeleteFilter = new RelationPredicateBucket(GLVoucherHeaderFields.TransID == item.TransID);       
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);

To


// delete header  This is Changed
    var vHeaderDeleteFilter = new RelationPredicateBucket(FNDCustomerDistributionFields.TransID == item.TransID);       
    uow.AddDeleteEntitiesDirectlyCall(typeof(GLVoucherHeaderEntity), vhDeleteFilter);

but i want to ask about why its work with FNDCustomerDistributionFields.TransID not GLVoucherHeaderFields.TransID Is there something strange !!!

In your original post, it's the opposite: you have FNDCustomerDistributionFields.TransID in the predicate for deleting GLVoucherHeader, which is wrong, as you should use GLVoucherHeaderFields.TransID.

I have no idea what FNDCustomerDistribution is btw, it's not mentioned in your explanation, nor do I understand why you would need that field in the routine at all, as you're deleting GLVoucherHeader entities, so you need fields from that entity.

Frans Bouma | Lead developer LLBLGen Pro