Refetch not complete

Posts   
 
    
asowles
User
Posts: 46
Joined: 23-Apr-2008
# Posted on: 16-Jul-2009 21:37:56   

We have an issue where we fetch an entity that is several layers deep, then make some changes to the entity, then save it with refetch set to true, but when we do, it doesn't get all of the child entities. Here is the code we use to fetch the entity:



public EmployeeEntity FetchEmployee(EmployeeEntity entityToFetch, bool withChildren)
        {
            EmployeeEntity employee = new EmployeeEntity(entityToFetch.CompanyId, entityToFetch.EmployeeId);
            IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.EmployeeEntity);
            RelationCollection rulesCollection = new RelationCollection();
            rulesCollection.Add(EmployeeEntity.Relations.EmployeeRulesEntityUsingEmployeeRulesId, JoinHint.Left);

            if (withChildren)
            {
                prefetchPath.Add(EmployeeEntity.PrefetchPathDepartment);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeRules, 0, null, rulesCollection);
                prefetchPath.Add(EmployeeEntity.PrefetchPathPayclass);
                prefetchPath.Add(EmployeeEntity.PrefetchPathFirstRelationshipType);
                prefetchPath.Add(EmployeeEntity.PrefetchPathSecondRelationshipType);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeTypes);
                IPrefetchPathElement2 environmentPrefetch = prefetchPath.Add(EmployeeEntity.PrefetchPathEnvironment);
                environmentPrefetch.SubPath.Add(EnvironmentsEntity.PrefetchPathInAudioCue);
                environmentPrefetch.SubPath.Add(EnvironmentsEntity.PrefetchPathOutAudioCue);
                environmentPrefetch.SubPath.Add(EnvironmentsEntity.PrefetchPathEnvironmentMessageRange)
                    .SubPath.Add(EnvironmentMessageRangeEntity.PrefetchPathMessageRanges)
                    .SubPath.Add(MessageRangesEntity.PrefetchPathAudioCue);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeAllowedDepartments).SubPath.Add(EmployeeAllowedDepartmentsEntity.PrefetchPathDepartment);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeBenefit).SubPath.Add(EmployeeBenefitEntity.PrefetchPathPaycode);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeAssignedTerminals);
                prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeCustomFields);
            }

            adapter.FetchEntity(employee, prefetchPath);

            return employee;
        }


When we fetch the entity using this code, everything works like it should. We have a generic save function that saves an entity that looks like this:



 public void SaveEntity(IEntity2 entity, bool refetch)
        {
            try
            {
                adapter.SaveEntity(entity, refetch);
            }
            catch (Exception ex)
            {
                throw DataExceptionFactory.CreateException(ex);
            }
        }


The problem is with the Paycode entity. The paycode entity is correct and complete when we fetch it using the first chunk of code. If we make a change and save it, the Paycode entity is null. We noticed that the SQL that is being generated is slightly different for the first fetch:

SELECT [DBA].[EmployeeBenefit].[CompanyID] AS [CompanyId], [DBA].[EmployeeBenefit].[EmployeeID] AS [EmployeeId], [DBA].[EmployeeBenefit].[BenefitPaycodeID] AS [BenefitPaycodeId], [DBA].[EmployeeBenefit].[HoursAllowed], [DBA].[EmployeeBenefit].[HoursTaken], [DBA].[EmployeeBenefit].[StartDate], [DBA].[EmployeeBenefit].[CreateDateTime], [DBA].[EmployeeBenefit].[LastUpdateDateTime], [DBA].[EmployeeBenefit].[SequenceNumber] FROM [DBA].[EmployeeBenefit] WHERE ( ( ( [DBA].[EmployeeBenefit].[CompanyID] = ? AND [DBA].[EmployeeBenefit].[EmployeeID] = ?)))

and the sql that is being generated for the refetch:

SELECT [DBA].[EmployeeBenefit].[CompanyID] AS [CompanyId], [DBA].[EmployeeBenefit].[EmployeeID] AS [EmployeeId], [DBA].[EmployeeBenefit].[BenefitPaycodeID] AS [BenefitPaycodeId], [DBA].[EmployeeBenefit].[HoursAllowed], [DBA].[EmployeeBenefit].[HoursTaken], [DBA].[EmployeeBenefit].[StartDate], [DBA].[EmployeeBenefit].[CreateDateTime], [DBA].[EmployeeBenefit].[LastUpdateDateTime], [DBA].[EmployeeBenefit].[SequenceNumber] FROM [DBA].[EmployeeBenefit] WHERE ( ( [DBA].[EmployeeBenefit].[CompanyID] = ? AND [DBA].[EmployeeBenefit].[EmployeeID] = ? AND [DBA].[EmployeeBenefit].[BenefitPaycodeID] = ?))

Another odd thing is that the other prefetch paths seem to be complete and it is only the Paycode entity that is null (not being refetched).

I am using Version 2.6 and runtime 2.6.09.0616.

Is there a reason why a refetch would not return the correct entity that is fully loaded? Right now we have set the refetch to false and immediately fetch the entity by hand, but aren't sure why we have to do this when the refetch should work.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Jul-2009 22:02:40   

I know it will be long, but please could you post all of the SQL generated, both for the inital fetch and the refetch ?

The SQL in your post seems to refer to the EmployeeBenefit entity rather than the PayCode itself.

Thanks

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 17-Jul-2009 10:49:45   

Refetch only refetches the data of the saved entity, not any child entities. If you want them to be refetched as well, you have to refetch the graph. You can either do that from the beginning or refetch the entity with the prefetch path into the same class instance but in that case, use a Context instance to make sure all the class instances are the same.

Frans Bouma | Lead developer LLBLGen Pro
asowles
User
Posts: 46
Joined: 23-Apr-2008
# Posted on: 17-Jul-2009 14:12:23   

Thank you, that makes sense.