Can't retrieve news item using fluent API
I'm a bit confused about when to use the fluent API or content managers. I just try one, and if it fails, use the other one. But I suspect that both are supposed to work, and if not, it's a bug.
For example, the following piece of code doesn't work and throws a System.InvalidOperationException ("Telerik.Sitefinity.News.Model.NewsItem with id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is not a draft."):
The reason why you can't access a published NewsItem with App.WorkWith().NewsItem(id) is because it provides the facade for draft elements (and yours is published). When you use App.WorkWith().NewsItems() this is a plural facade for all News elements and when your Get one of them, it has a Draft status (up until you publish it). The already published item is kept in a master object, which is replaced with the new Drafted one after publishing. This means that when you get the News Item (by title for example) and then get its ID, it returns the drafted ID (and NewsItems().Published() doesn't find it as a published item).
So, if you need to find the item by the ID (and it is published) you will have to use the following code.
Thanks for the explanation. Confusing, though...
Out of curiosity, why do you recommend Where + First rather than FirstThat?
Not anything in particular, just the Where() . First() methods are more popular and there is a smaller possibility for them to cause problems.All the best,