The delete action of an entity failed, probably due to the set delete restriction.

Posts   
 
    
silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 01-Aug-2008 12:33:42   

I am getting this:

{"The delete action of an entity failed, probably due to the set delete restriction. The entity which failed is enclosed."}

The case is strange.

I have 2 databases, all I want to do is save the entity into both (and also delete from both).

But I've found that I can't use the same entity for that; so I create another one and try and do it (it's working for saving).

But when deleting (using a unique index with 2 fields) I get the above error message.

Code is basically:

TheEntity fl2 = new TheEntity (); fl2.Field1 = field1; fl2.Field2 = field2;

adapter.DeleteEntity(fl2, fl2.ConstructFilterForUCForField2Field2());

why am i getting this message? thanks.

also, if there is any way to save the same entity into two different (but same schema) dbs i'd like to know. thanks.

silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 01-Aug-2008 13:27:49   

interestingly this works:

adapter.FetchEntityUsingUniqueConstraint(fl2, fl2.ConstructFilterForUCForField1Field2()); adapter.DeleteEntity(fl2);

where this (as above) doesn't:

adapter.DeleteEntity(fl2, fl2.ConstructFilterForUCForField1Field2());


obviously that method is stupid (the first one) because it's doing a useless fetch. so how can i delete directly based on unique index?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Aug-2008 19:21:12   

The DeleteEntity method needs the Primary Key of the Entity to perform the delete successfully. If you want to do that in one-go (you don't have the PK and you don't want to do a fetch), please use DeleteEntitiesDirectly:

adapter.DeleteEntitiesDirectly("CustomerEntity", someUCFilter);

I don't think the method is stupid smile , maybe we should read the docs wink

David Elizondo | LLBLGen Support Team
silky avatar
silky
User
Posts: 38
Joined: 03-Feb-2008
# Posted on: 02-Aug-2008 02:28:45   

why does it need the primary key? i have a unique index? I can use that as a unique fetch why can't i use it as a unique delete?

anyway, i now use this:

adapter.DeleteEntitiesDirectly("Entity", new RelationPredicateBucket(fl2.ConstructFilterForUCForField1Field2()));

which works. thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Aug-2008 04:16:22   

Good it works finally. I really don't know why you need a PK and not a UC. I think it is because it could be accomplish any delete operation with that two methods.

I think you can Fetch using PK and UC because after the fetch you expect see the entity filled with values. It's different with Delete. Anyway, it would be easy to create a method that wraps the DeleteEntitiesDirectly for a passed Entity to delete. Someone could add that to custom templates if really need it simple_smile

David Elizondo | LLBLGen Support Team