|
Rank: Advanced Member Groups: Registered
Joined: 12/16/2011(UTC) Posts: 35 Location: Ohio, USA
|
So I was in fact able to use LINQ/Lamda WITH the data rules... just had to do some casting, and treat the data slightly differently...
Turns out, if Paging is enabled in the Data Rules, the object being returned is of type Kooboo.CMS.Sites.DataRule.DataRulePagedList, which implements IEnumerable<T> (allowing LINQ), but also seems to use dynamic objects.
Alternatively, if Paging is NOT enabled, the data rule returns an object of type Kooboo.CMS.Content.Models.ContentBase[].
Good news, is that either way, I could use the fieldname as an index to the object, when dealing with linq... took some casting (since it seems the index returns an 'object'), but I was able to do the following:
((Kooboo.CMS.Sites.DataRule.DataRulePagedList)(ViewBag.BlogPosts)).Where(p => (p["PublishDate"] as DateTime?).HasValue && (p["PublishDate"] as DateTime?).Value <= DateTime.Now)
Since I was also casting the return types, I also had to change the way the properties were referenced in the rest of the cshtml, from using the dynamic object format (obj.property) to the index (obj["property"]).
Not sure if this is better or worse performance than using dynamic objects (since I suspect that they use reflection), and much cleaner than using reflection myself (considered using p.GetType().GetProperty("PublishDate").GetValue(p)).
I'll end up doing a bit of a post mortem on my blog as soon as it starts to go live.
|