IsDirty and PrefetchPath

Posts   
 
    
obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 14-Jan-2010 13:37:52   

Hello. I noticed that if I load an entity by calling FetchUsingPK and specifying a prefetch path, the IsDirty property of the entity is raised to True. It remains False if no prefetch path is specified. Is that by design? If yes, why that happens?

I'm using SelfServicing and runtime v2.6.10.105.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Jan-2010 23:49:20   

Is this the .IsDirty property of the entity at the top of the graph ? Can you post a code snippit which demonstrates how you are calling this ?

Thanks

Matt

obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 15-Jan-2010 07:44:18   

Here's an example:


PrefetchPath path = new PrefetchPath(EntityType.ReportEntity);
path.Add(ReportEntity.PrefetchPathSiteWorkType);
ReportEntity re = new ReportEntity();
if (!re.FetchUsingPK(reportID, path, null, null))
     throw new Exception(string.Format("The specified report {0} cannot be found.", reportID));

// Reset the dirty flag because loading the entity with a prefetch path makes it 'dirty'.
// Not sure if it's LLBL by design or not but we don't want that.
re.IsDirty = false;

The relation between Report and SiteWorkType is via a Report.SiteWorkTypeID FK.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Jan-2010 09:05:13   

Reproduced. We are looking into it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 15-Jan-2010 10:07:37   

Odd indeed. The FK field is marked as dirty. So when I do:


[Test]
public void FetchWithPrefetchPathIsDirtyTest()
{
    PrefetchPath path = new PrefetchPath(EntityType.OrderEntity);
    path.Add(OrderEntity.PrefetchPathCustomers);
    OrderEntity o = new OrderEntity();
    Assert.IsFalse(o.IsDirty);
    Assert.IsTrue(o.IsNew);
    Assert.IsTrue(o.FetchUsingPK(10254, path));
    foreach(EntityField field in o.Fields)
    {
        if(field.IsChanged)
        {
            Console.WriteLine("Field '{0}' is marked as changed", field.Name);
        }
    }
    Assert.IsFalse(o.IsDirty);   // <<<< fails.
    Assert.IsFalse(o.IsNew);
}

It will say 'CustomerId' and fail on the isdirty assert.

When I do:


[Test]
public void FetchWithPrefetchPathIsDirtyTest2()
{
    PrefetchPath path = new PrefetchPath(EntityType.OrderEntity);
    path.Add(OrderEntity.PrefetchPathCustomers);
    OrderCollection orders = new OrderCollection();
    Assert.IsTrue(orders.GetMulti((OrderFields.OrderId == 10254), path));
    Assert.AreEqual(1, orders.Count);
    OrderEntity o = orders[0];
    foreach(EntityField field in o.Fields)
    {
        if(field.IsChanged)
        {
            Console.WriteLine("Field '{0}' is marked as changed", field.Name);
        }
    }
    Assert.IsFalse(o.IsDirty);
    Assert.IsFalse(o.IsNew);
}

then IsDirty is not set. So it's not the prefetch path code, but I suspect the order in which things happen, will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 15-Jan-2010 10:26:36   

Fixed it. The internal method doing the fixing was fetching the prefetch path before the entity was marked as fetched (it was still 'new'), so Fk syncing took place. Strange that this bug has been in the code for so long (4-5 years). See attached dll.

Frans Bouma | Lead developer LLBLGen Pro
obzekt
User
Posts: 60
Joined: 29-Apr-2004
# Posted on: 15-Jan-2010 16:56:38   

Glad you found it. Thanks for the quick response!