- Home
- LLBLGen Pro
- Bugs & Issues
Getting entity out of sync exception
Joined: 17-Nov-2011
Hi there, Product: LLbLGen Pro v3.1 Final Runtime Library: 3.1.11.907 Database: SQL Server 2008/ Oracle 11i We use .NET 4.0 framework and VB.Net
We are trying to fetch the entity using the following code:
adapter.FetchEntity(empFormEntity, formPreFetchPath)
If the entity is not found we are getting an exception ORMOutOfSyncException- "The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance."
The entity with the Id we are trying to fetch is not found and hence the Sql query returns an empty row. But we get exception in code.
When we try to do the same kind of fetch for another entity it returns empty row from the database and does not cause any exception.
adapter.FetchEntity(loginEntity, loginPreFetchPath)
Stack Trace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetValue(Int32 fieldIndex, Boolean returnDefaultIfNull) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 2514 at Grb.Framework.Business.Lower.EntityClasses.EmpFormXfdfEntity.get_EmployeeId() in c:\Mywork\Production\AssistWeb\Framework\Business.Lower\DatabaseGeneric\EntityClasses\EmpFormXfdfEntity.cs:line 601 at Grb.Framework.Business.Lower.Authorization.FormAuthorizer.CanLoadEntity(IEntityCore entity) in c:\Mywork\Production\AssistWeb\Framework\Business.Lower\Authorization\Authorization\FormAuthorizer.cs:line 24 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.OnCanLoadEntity() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 3024 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.CallOnCanLoadEntity() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityBase2.cs:line 1917 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingFilter(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath, Context contextToUse, IRelationPredicateBucket filter, ExcludeIncludeFieldsList excludedIncludedFields) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4826 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1830 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1783 at Grb.PlugIn.Assist.Business.BusinessManager.GetEmployeeFormXfdfEntity(Int32 formId) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Business\BusinessManager.vb:line 3538 at Grb.PlugIn.Assist.Business.BusinessManager.GetEmployeeFormXfdfEntity(Int32 formId) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Business\BusinessManager.vb:line 3545 at Grb.PlugIn.Assist.Business.BusinessManager.GetFormXfdfEntity(Int32 formId) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Business\BusinessManager.vb:line 3503 at Grb.PlugIn.Assist.Business.BusinessManager.GetFormXfdfEntity(Int32 formId) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Business\BusinessManager.vb:line 3517 at Grb.PlugIn.Assist.Business.BusinessManager.SetFormXfdfEntity(Int32 formId, Int32 employeeId, Int32 loginId, String formType, String formTypeName, String name, String data, Boolean isNewForm, String isCustomForm, String assistDomainId) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Business\BusinessManager.vb:line 3914 at Grb.PlugIn.Assist.Presentation.FormGenerator.Page_Load(Object sender, EventArgs e) in C:\Mywork\Production\AssistWeb\PlugIn\Assist\Presentation\UISandbox\FormGenerator.ascx.vb:line 184
From the ORM profiler, the following is the query before the exception: SELECT [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[CREATED_TIMESTAMP] AS [CreatedTimestamp], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[CREATED_USER_ID] AS [CreatedUserId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[DATA] AS [Data], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMP_FORM_TEMPLATE_ID] AS [EmpFormTemplateId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMPLOYEE_ID] AS [EmployeeId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[GUID] AS [Guid], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[ID] AS [Id], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[LAST_UPDATED_TIMESTAMP] AS [LastUpdatedTimestamp], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[LAST_UPDATED_USER_ID] AS [LastUpdatedUserId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[NAME] AS [Name], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_build] AS [VersionBuild], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_major] AS [VersionMajor], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_minor] AS [VersionMinor], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_revision] AS [VersionRevision], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_TEMPLATE].[TYPE] AS [Type], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_TEMPLATE].[TYPE_NAME] AS [TypeName], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[MODIFIED_TIMESTAMP] AS [ModifiedTimestamp] FROM ( [OUR_DB].[OUR_SCHEMA].[EMP_FORM_TEMPLATE] INNER JOIN [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF] ON [OUR_DB].[OUR_SCHEMA].[EMP_FORM_TEMPLATE].[ID] = [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMP_FORM_TEMPLATE_ID]) WHERE (([OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMPLOYEE_ID] = @p1))
The query from SQL profiler is: exec sp_executesql N'SELECT [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[CREATED_TIMESTAMP] AS [CreatedTimestamp], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[CREATED_USER_ID] AS [CreatedUserId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[DATA] AS [Data], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMP_FORM_TEMPLATE_ID] AS [EmpFormTemplateId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[EMPLOYEE_ID] AS [EmployeeId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[GUID] AS [Guid], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[ID] AS [Id], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[LAST_UPDATED_TIMESTAMP] AS [LastUpdatedTimestamp], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[LAST_UPDATED_USER_ID] AS [LastUpdatedUserId], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[MODIFIED_TIMESTAMP] AS [ModifiedTimestamp], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[NAME] AS [Name], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_build] AS [VersionBuild], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_major] AS [VersionMajor], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_minor] AS [VersionMinor], [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[version_revision] AS [VersionRevision] FROM [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF] WHERE ( ( [OUR_DB].[OUR_SCHEMA].[EMP_FORM_XFDF].[ID] = @p1))',N'@p1 int',@p1=13 Thanks, Dharini
Joined: 17-Nov-2011
Hello Walaa, We found that the problem was in our Authorizer code. We were trying to get some fields from the empForm entity which was already not found in the database and hence it threw the OutOfSync exception.
Thanks for your help. Dharini
Hi Dharini,
Should we assume you have this working now? The OutOfSync exception is normal if you indeed don't receive any entities in the fetch. The reason is that you can't trust or access fields that don't exist. To overcome this you should perform a check:
adapter.FetchEntity(order);
if (order.IsNew)
{
// the entity isn't in DB, so manage the situation
return ...;
}
// the entity is in DB, so continue...
//...