IsDirty is always returning trueIsDirty is always returning true
Old forum URL: forums.lhotka.net/forums/t/5663.aspx
dculler posted on Thursday, October 23, 2008
I'm just getting started on CSLA and I'm having some trouble with IsDirty. I've written a small test project that creates a new business object, saves it, and prints the value of it's IsDirty property to the console. For some reason, this is always returning true even though I can see the _isDirty member being set to false when MarkClean() is called as a result of calling my object's Save() method. I'm using CSLA.net 3.5.2.
I've tried using IsSelfDirty, and calling MarkClean() manually in my DataPortal_Insert method, and am not having any luck.
I've included my small test program below. Can anyone tell me what I'm missing? Thanks in advance for any help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
namespace Csla_IsDirty_Test
{
class Program
{
static void Main(string[] args)
{
BusObject obj = BusObject.NewBusObject();
Console.WriteLine(obj.IsDirty); //Prints true
Console.WriteLine("Saving ...");
obj.Save();
Console.WriteLine(obj.IsDirty); //Prints true
Console.ReadLine();
}
}
[Serializable()]
public class BusObject : BusinessBase<BusObject>
{
#region Factory Methods
public static BusObject NewBusObject()
{
return DataPortal.Create<BusObject>();
}
private BusObject()
{ /*Require use of factory methods*/ }
#endregion Factory Methods
#region Data Access
[RunLocal()]
protected override void DataPortal_Create() { }
protected override void DataPortal_Insert()
{
}
protected override void DataPortal_Update()
{
}
#endregion Data Access
}
}
skagen00 replied on Thursday, October 23, 2008
Try:
obj = obj.Save();
dculler replied on Thursday, October 23, 2008
Ah, simple mistake. That did the trick, thanks for the help.
JoeFallon1 replied on Thursday, October 23, 2008
You have made the #1 error is CSLA coding - so you are in good company.
Here is the problem:
obj.Save();
should be:
obj = obj.Save();
You have to replace the obj reference when you save it!
Joe
Copyright (c) Marimer LLC