Hi, we've recently updated from LLBLGen 1.x to LLBLGen 2.0, and I've found a difference in behavior. In LLBLGen 2.0, when you set a field null on a table-based entity, the field is not set and IsChanged remains false.
I noticed the thread http://llblgen.com/tinyforum/Messages.aspx?ThreadID=10019&StartAtMessage=0, but this appears to be different. I am using a table-based entity, adapter templates, and the SourceColumnIsNullable flag is true. Database is SQL Server 2005.
Here's the test code to reproduce.
[Test]
public void SetFieldToNull()
{
// set cost method to A
{
AccountEntity acct = new AccountEntity(0);
adapter.FetchEntity(acct);
acct.CostMethod = "A";
adapter.SaveEntity(acct);
}
// now set to null
// in LLBLGen 1 this works, but in LLBLGen 2 you need to add either one of the commented-out lines below
{
AccountEntity acct = new AccountEntity();
acct.AccountID = 0;
acct.IsNew = false;
// acct.CostMethod = "";
acct.CostMethod = null;
// acct.Fields["CostMethod"].IsChanged = true;
Assert.IsTrue(acct.Fields["CostMethod"].IsChanged); // this assertion will fail
adapter.SaveEntity(acct);
}
// now check - should be null (or empty since that is the Type default value returned by the property)
{
AccountEntity acct = new AccountEntity(0);
adapter.FetchEntity(acct);
Assert.AreSame(string.Empty, acct.CostMethod); // if we comment out the assertion above, all of these would fail
Assert.AreSame(null, acct.Fields["CostMethod"].CurrentValue);
Assert.IsTrue(acct.Fields["CostMethod"].IsNull);
}
}
Here is the defintion of Account.CostMethod:
base.AddElementFieldMapping( "AccountEntity", "CostMethod", "CostMethod", [b]true[/b], (int)SqlDbType.Char, 1, 0, 0, false, "", null, typeof(System.String), 46 );
The same behavior exists regardless of whether I set the property to null, or if I use SetNewFieldValue(...,null).
One last note - we are using an add-in that does not expose our properties as nullable types, for backwards compatibility with our code which was based on LLBLGen 1.x. Not sure if this is related.
I noticed in the LLBLGen code (thanks Reflector!) that the logic in FieldUtilities.DetermineIfFieldShouldBeSet() has changed from 1.x to 2.0. Actually 1.x did not have this method, but just had a if clause right inside SetNewFieldValue. My guess is that this change in behavior is what is causing the problem.
Thanks in advance.