Fetching additional entities into a loaded entity causes it be become 'out of sync'

Posts   
 
    
Pilo
User
Posts: 13
Joined: 07-Oct-2014
# Posted on: 07-Mar-2018 11:17:23   

Sometimes I know I need to load additional sub-entities into an existing entity (or make sure they are prefetched regardsless if they were pre-loaded or not). I use the following code to realize this:

using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntity(entityThatWasAlreadyLoaded, PrefetchPaths.GetPathForQuotationWithLinesAndSubObjects()); entityThatWasAlreadyLoaded.IsDirty = false; }

PrefetchPaths.GetPathForQuotationWithLinesAndSubObjects is a method that composes a set of sub paths to fetch.

I noticed that the loading of additional sub objects works, but it will mark the owning object (entityThatWasAlreadyLoaded) as "Dirty" and this will cause 'out of sync' exceptions when reading the properties of the owning object. I have to explicitly set the owning object to IsDirty = false after the additional fetch, even though the data properties (fields) of the owning object should not be changed by this operation.

How should I go about loading additional data into a pre-loaded entity?

I'm using LLBL version 5.1 with SQL Server, Adapter model, no custom templates

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Mar-2018 19:16:30   

What's the problem caused by having IsDirty flagged to true?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Mar-2018 11:16:30   

Also keep in mind that calling FetchEntity with an already fetched entity will fetch it again, so it's not really 'just fetching the additional paths', it also fetches entityThatWasAlreadyLoaded again.

Frans Bouma | Lead developer LLBLGen Pro
Pilo
User
Posts: 13
Joined: 07-Oct-2014
# Posted on: 09-Mar-2018 09:17:12   

Thank you for the insights. I will adjust the code accordingly.