Oct 19, 2013 at 12:53 AM
Edited Oct 19, 2013 at 12:54 AM
I'm programmatically updating a Boolean field on a content item. The value of the Data field in the ContentItemVersionRecord table is updated correctly, which is great! However, I have a Query which filters on this Boolean field, and the associated content
item is still included in the query's results, even though it should not be. Indeed, when previewing the query (in the dashboard), I can see that the field is False, indicating that the content item has been updated. Yet the query itself should exclude this
result because the filter is configured to only include items where this field is True.
This is how I update the field value:
var contentItem = _orchardServices.ContentManager.Get(myContentItemId);
var myPart = contentItem.Parts.First(p => p.PartDefinition.Name == "MyContentType");
var availableField = myPart.Fields.First(f => f.Name == "Available");
((dynamic)availableField).Value = false;
_orchardServices.ContentManager.Publish(contentItem); // this line does not appear to be necessary to update the database
My Query is configured to only include results where the "Available" field is True.
Now, when I use the built-in content editor to edit the content item and set the Available field to False, the item does not come back in the query result, which is correct behavior.
But when I use the code snippet above to update the Available field to False, the item comes back in the query result, which is incorrect. And yet the item in the results does indeed have Available set to False.
So for some reason the result is not being excluded from the Query when I use the programmatic approach above. Surely I'm missing something simple. Help!