Hi,
I'd always wondered what would happen if you created an entity marked IsNew = false, set the primary key and then only set 1 or 2 properties. What would happen, would those 1 or 2 properties be set and everything else made to be null. The answer turned out to be no, it only updates the fields you set. This is awesome! Many a time to projects past I have loaded the entity, set a couple of fields and saved it back to the DB... oops!
However I ran into a bit of hiccup with this when working with nullable typed fields.
var siteCheckListItem = new SiteCheckListItemEntity();
siteCheckListItem.SiteOwnershipId = (int)vreSite.CurrentOwnershipId;
siteCheckListItem.CheckListItemId = checkListItem.CheckListItemId;
siteCheckListItem.IsNew = false;
siteCheckListItem.IsDirty = true;
if (checkListItemId != null && checkListItemId.Contains(checkListItem.CheckListItemId))
{
siteCheckListItem.IsComplete = true;
siteCheckListItem.DateCompleted = DateTime.Now;
siteCheckListItem.MarkedCompleteById = CurrentUserId;
}
else
{
siteCheckListItem.IsComplete = false;
siteCheckListItem.DateCompleted = null;
siteCheckListItem.MarkedCompleteById = null;
}
When the "else" branch executes it sets DateCompleted and MarkedCompleteById to null however LLBL seems to consider that a no-op as it sets IsComplete to false but ignores the other two field changes.
I've found that doing this:
siteCheckListItem.Fields["DateCompleted"].IsChanged = true;
siteCheckListItem.Fields["MarkedCompleteById"].IsChanged = true;
forces LLBL to includes those fields in the update statement. However... I don't like this much. Is there an alternative that doesn't leave me writing an extra line of code for each property I set?