The entity is out of sync - strange.

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 30-Jun-2010 11:08:39   

3.0 Final (June 28 2010) Runtime version: v2.0.50727 DB: postgresql 8.4.2

Hi,

i have a following methods:

protected void FetchEntity(IEntity2 entityToFetch)
        {
            using (DataAccessAdapterBase adapter = CreateAdapter())
            {
                adapter.FetchEntity(entityToFetch);
            }
        }


public void SaveLLBLGen(IEntityBase entity, bool refetchAfterSave = false)
        {
            using (DataAccessAdapterBase adapter = CreateAdapter())
            {
                adapter.SaveEntity((IEntity2)entity, refetchAfterSave, true);
            }
        }


public IContentMainContentEntity GetContentLLBLGen(long idMainContent)
        {
            MainContentEntity ret = new MainContentEntity(idMainContent);

            FetchEntity(ret);

            
            return ret;
        }

When I'll try to run the following test method:

var content = contentDao.GetContentLLBLGen(3807967);

contentDao.SaveLLBLGen(content);

The following error occurs:

The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance.

This is very strange - I've didn't modified an object at all. What could be wrong?

Stack trace:

 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetValue(Int32 fieldIndex, Boolean returnDefaultIfNull) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 2487
   at AplusC.DataModel.V2.EntityClasses.MainContentEntity.get_CreatedBy() in C:\projects\TFS\Steve\Server\DataAccessLayer\DatabaseGeneric\EntityClasses\MainContentEntity.cs:line 1073
   at AplusC.DataModel.V2.EntityClasses.CommonEntityBase.MarkTrackingData(IEntityBase entity, String idUser) in C:\projects\TFS\Steve\Server\DataAccessLayer\DatabaseGeneric\EntityClasses\CommonEntityBasePartial.cs:line 44
   at AplusC.DataModel.V2.EntityClasses.CommonEntityBase.OnBeforeEntitySave() in C:\projects\TFS\Steve\Server\DataAccessLayer\DatabaseGeneric\EntityClasses\CommonEntityBasePartial.cs:line 17
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.CallOnBeforeEntitySave() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 1974
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.OnBeforeEntitySave(IEntity2 entitySaved, Boolean insertAction) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 3933
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1370
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1326
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, Boolean recurse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1174
   at AplusC.Common.Implementation.WithDependencies.Dao.BaseLLBLGenDAO.SaveLLBLGen(IEntityBase entity, Boolean refetchAfterSave, String idUser) in C:\projects\TFS\Common\dotNet\TvMan.CommonBusiness\BaseLLBLGenDAO.cs:line 81
   at TestApp.Program.MiloszTest() in C:\projects\TFS\Steve\Server\TestApp\Program.cs:line 84
   at TestApp.Program.Main(String[] args) in C:\projects\TFS\Steve\Server\TestApp\Program.cs:line 44
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Regards, MiloszeS

[Edit]

It seams, that I referenced to the db with old schema. It was weird, because an entity was correctly loaded, but it couldn't be saved even if I didn't changed anything.