I reproduced it on the latest v4: the order matters.
[TestMethod]
public void ForceDBValue1()
{
var customer = new CustomerEntity();
var index = (int)CustomerFieldIndex.Country;
customer.Fields.ForcedValueWrite(index, "GTM", "CRC");
Assert.AreEqual("CRC", customer.Fields.GetDbValue(index));
}
[TestMethod]
public void ForceDBValue2()
{
var customer = new CustomerEntity();
var index = (int)CustomerFieldIndex.Country;
customer.Fields.MarkAsFetched();
customer.Fields.ForcedValueWrite(index, "GTM", "CRC");
customer.Fields.SetIsChanged(index, true);
Assert.AreEqual("CRC", customer.Fields.GetDbValue(index));
}
[TestMethod]
public void ForceDBValue3()
{
var customer = new CustomerEntity();
var index = (int)CustomerFieldIndex.Country;
customer.Fields.MarkAsFetched();
customer.Fields.SetIsChanged(index, true);
customer.Fields.ForcedValueWrite(index, "GTM", "CRC");
Assert.AreEqual("CRC", customer.Fields.GetDbValue(index));
}
Only the last test passes. The second one should, but I think it doesn't because of this (**VolatileEntityFieldsDataContainer.cs:218**):
public void SetIsChanged(int index, bool value)
{
if(value && this.DbValuesAreValid && !_changedFlags[index])
{
// value has changed, make sure the db value, which is in current value (as we keep 1 value from the db around), is copied
// over to dbvalues this time.
SetDbValue(index, _currentValues[index]);
}
_changedFlags[index] = value;
}
We will look into this (whether this is expected, for some reason).