Error on Collection<T>.Remove() ORMGeneralOperationException

Posts   
 
    
can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 29-Apr-2009 18:07:41   

Hello,

I have an entity collection with 3 entities inside it.

When I issue a .Remove(entity) on that collection, I am receiving an exception:

Message

The remove failed, as List<T>.Remove returned false

Source

A first chance exception of type 'SD.LLBLGen.Pro.ORMSupportClasses.ORMGeneralOperationException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll

StackTrace

at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Remove(T item)\r\n   
....
.... application level 

I was able to export the collection and entity that was being deleted out to xml and recreate the issue through a reconsititution of the serialized objects.

Checking the object ID of the entities in the collection, and the object id of the entity being deleted, the object id exists in the collection:

? entity.ObjectID
{ac486595-8881-4f58-ac02-0a5f2284b5b4}
? collection[0].ObjectID
{173da0ec-5fd5-4057-8b29-7e5f0209bbe6}
? collection[1].ObjectID
{ac486595-8881-4f58-ac02-0a5f2284b5b4}

Any thoughts on why this entity cannot be deleted?

Thanks.

Can1

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 29-Apr-2009 18:24:59   

One more piece of information:

? collection.Contains(entity) returns false.

How is it determining that the entity is not contained in the collection when the object_id does exists?

Can1

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 29-Apr-2009 19:36:39   

Ok. More information. It looks like a serialization issue. If you have a collection, and serialize one of the objects inside it, then try to do a collection.remove(de-serialized object), you receive the error. Even though the serialized and deserialized versions of the object have the same objectid, then have different hashcodes and the remove method uses some type of checking logic to determine if the object exists in the collection.

This poses problems when dealing with serialized and deserialized objects for us. Any thoughts? I have hacked a short-term solution to remove the object from the collection based on object_id in the interm.

Thanks.

Can1.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 30-Apr-2009 11:29:13   

Matching/finding an entity inside a collection is done using the PK value, unless the entity was new. Does the serilaized and deserialized versions have the same PK value?

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 30-Apr-2009 15:46:26   

The entity and collection has not yet been persisted to disk, so they have the same PK id at this point, none.

So it appears that it is using something other than pk id or object_id to find the entity in the collection for the remove action. When I take an entity, serialize it, deserialize it, it's gethashcode() is different so something is different about the entity after serialization it appears, and whatever that is, looks like it is used by the EntityCollection<T>.remove() method?

Can1

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-May-2009 05:24:14   

LLBLGen version and runtime library version? (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

David Elizondo | LLBLGen Support Team
can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 01-May-2009 15:01:00   

LLBL 2.6, SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version 2.6.9.313.

Can1

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-May-2009 22:13:06   

I think I found it: If entity is new, no values are compared, but the physical objects are compared (object.Equals()), because new entities can look the same, value wise due to identity fields which are all 0, however which are physical different entities (object wise). So it may be that indeed the entities are not physically the same due to the serialization. So at that point is the object.Equals that determines that in the find of the Remove routine.

As a workaround you should continue using your new routine or perform a FindMatches on the collection with a unique predicate (some fields you know you will find the entity) and then remove it.

David Elizondo | LLBLGen Support Team