Error when cloning entity

Posts   
 
    
Posts: 33
Joined: 31-May-2005
# Posted on: 23-Sep-2005 22:16:30   

Hello,

I am trying to clone an entity and running into problems ... I wrote a quick sample to illustrate:

ItemEntity e1 = new ItemEntity(); ItemEntity e2 = new ItemEntity(); e2.Fields = ((EntityFields)_currentItem.Fields).Clone();

error: Cannot implicitly convert type 'object' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2'. An explicit conversion exists (are you missing a cast?)

This was the code I saw in some earlier messages ... any thoughts?

Thanks, Josh Lindenmuth

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 24-Sep-2005 01:03:00   

JoshLindenmuth wrote:

Hello,

I am trying to clone an entity and running into problems ... I wrote a quick sample to illustrate:

ItemEntity e1 = new ItemEntity(); ItemEntity e2 = new ItemEntity(); e2.Fields = ((EntityFields)_currentItem.Fields).Clone();

error: Cannot implicitly convert type 'object' to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields2'. An explicit conversion exists (are you missing a cast?)

This was the code I saw in some earlier messages ... any thoughts?

Thanks, Josh Lindenmuth

.Clone() is an implementation of ICloneable and returns an object, so you'll need to perform another cast for the object returned from Clone(). I did notice, however, that you're intermingling Self-Servicing and Adapter implementations; you'll probably want to change "EntityFields" to "EntityFields2".

Jeff...

Posts: 33
Joined: 31-May-2005
# Posted on: 18-Oct-2005 19:10:00   

The clone logic is now working, however, when we go to save the cloned entity, the fields are null. The entity fields are as expected before saving, but when they are saved all the fields (except key fields) are null.

For example:

Console.WriteLine("User = " + clonedEntity.UserName); <-- Returns 'User = Josh' adapter.Save(clonedEntity, true); Console.WriteLine("User Name = " + clonedEntity.UserName); <-- Returns 'User = '

What are we doing wrong? Thanks, Josh Lindenmuth

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Oct-2005 20:47:02   

Are the fields' IsChanged flags set to true?

Frans Bouma | Lead developer LLBLGen Pro