Print Page | Close Window

POCO Merge Failure after Save

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2134
Printed Date: 13-Mar-2025 at 6:59am


Topic: POCO Merge Failure after Save
Posted By: rhaney
Subject: POCO Merge Failure after Save
Date Posted: 07-Sep-2010 at 2:15pm
I've created a simple POCO class to support user defined fields in my DevForce application.  I can get instances of the POCO class into the UI, and push updates back to the server via the SaveChanges method, but an exception is always raised on the client side after my PocoSaveAdapter executes.
 
My POCO object is pretty simple:
 
CustomField
  int : Id
  string : Name
  string : Value
 
Id is marked with the [Key] attribute.
 
Is there something I am missing?
 
Here is the exception:
 
IdeaBlade.EntityModel.EntityManagerSaveException: EntityManager merge failure: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at IdeaBlade.Core.MemberInfoFns.BuildPropertySet(PropertyInfo property)
   at IdeaBlade.EntityModel.EntityProperty.get_SetFunc()
   at IdeaBlade.EntityModel.PocoEntityWrapper.CopyValues(Object sourceEntity, Object destEntity)
   at IdeaBlade.EntityModel.PocoEntityWrapper.ReplaceCurrentOnLoadCore(EntityWrapper sourceWrapper)
   at IdeaBlade.EntityModel.EntityWrapper.ReplaceCurrentOnLoad(EntityWrapper sourceEntity)
   at IdeaBlade.EntityModel.EntityWrapper.LoadEntity(EntityWrapper sourceWrapper, MergeStrategy mergeStrategy)
   at IdeaBlade.EntityModel.EntityGroup.LoadEntity(EntityWrapper sourceWrapper, MergeStrategy mergeStrategy, Boolean& rowUpdated)
   at IdeaBlade.EntityModel.EntityMerger.MergeEntityCore(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup)
   at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
   at IdeaBlade.EntityModel.EntityMerger.<>c__DisplayClass1.<MergeEntities>b__0(EntityWrapper sourceWrapper)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at IdeaBlade.EntityModel.EntityMerger.Merge(IEnumerable`1 sourceEntityWrappersGroupedByType, NavigationContext context)
   at IdeaBlade.EntityModel.EntityMerger.Merge(EntityManager targetManager, IEnumerable`1 sourceEntityWrappersGroupedByType, MergeStrategy mergeStrategy, MergeType mergeType)
   at IdeaBlade.EntityModel.EntityManager.SaveEntitiesPostProcessing(SaveWorkState workState)
   --- End of inner exception stack trace ---
   at IdeaBlade.EntityModel.AsyncProcessor`1.<>c__DisplayClass2.<.ctor>b__0(TArgs args)
   at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
   at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)    
Line: 56
Char: 13
Code: 0



Replies:
Posted By: rhaney
Date Posted: 07-Sep-2010 at 2:17pm
FYI, this exception is raised in 6.0.4 and 6.0.5.


Posted By: davidklitzke
Date Posted: 08-Sep-2010 at 11:28am
Have you initialized the value of the id field?


Posted By: rhaney
Date Posted: 08-Sep-2010 at 12:07pm
Yes, the correct entity is updated during the save procedure in my PocoSaveAdapter class.
 
I can retrieve these POCO objects, modify them at the client, verify the entity state has changed, and persist the changes via the SaveChanges method.  At some point after the changes have been saved, the EM throws an exception on the client side (see the above exception).
 
I have a method defined as follows:
 
public void UpdateCustomField(CustomField current, CustomField original)
 
If I set a breakpoint at the beginning of this method, both "current" and "original" are fully populated objects, with the same ID.  This method executes without exceptions.  After updating and receiving the exception, if I restart my application I can pull up the entity and verify the changes were persisted.
 
The DevForce internal post save client-side merge operation is failing for POCO objects only.  If I don't modify a POCO object, everything works as expected.
 
It might be worth noting that I couldn't get an EntityServerPocoSaveAdapter implementation to be discovered, but the convention based approach outlined in the wiki at http://drc.ideablade.com/xwiki/bin/view/Documentation/POCOSupportInDevForce -  worked.
 
I'd prefer the EntityServerPocoSaveAdapter approach, due to the BeforeSave and AfterSave overrides.



Print Page | Close Window