Fluent Query: News Items by Category
I am building a simple news scroller in a usercontrol and trying to figure out how to pull only news items assigned to a specific category. I have everything working fine pulling all live news items (App.WorkWith().NewsItems().Where(n => n.Status = ContentLifecycleStatus.Live), but can't find a way to tack on a filter by category. I've spent an entire day trying to figure this out. Any assistance for a Sitefinity/Fluent/Linq newb is appreciated!
Yeah it's weird...not very fluent ATM :)
Please vote on the issue I have on PITS for this, :)
Here's how to do it though
if
(!
this
.IsDesignMode() && !
this
.IsBackend())
if
(!HttpContext.Current.Request.Url.ToString().Contains(
"PagesApprovalWorkflow"
))
if
(
this
.CategoryID != String.Empty)
var rotatorCategory =
new
Guid(
this
.CategoryID);
var content = App.WorkWith()
.NewsItems()
.Where(
ci => ci.GetValue<IList<Guid>>(
"Category"
).Contains(rotatorCategory) &&
ci.Status ==
Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Get();
Rotator1.DataSource = content;
Rotator1.DataBind();
else
this
.Controls.Add(
new
LiteralControl(
"<div color='red'>You need to go into Edit mode to specify the CategoryID which contains the Rotator items</div>"
));
Thanks for the reply, Steve. You'll have to forgive me though as I am a complete newbie to Sitefinity, Fluent, Linq and c#. My background is in ASP.Net VB webforms based development. So where do I get the CategoryID mentioned?? I have no idea what my CategoryID's are and would prefer to refer to them by name (string). Is this even possible?
Thanks again for your help!
Oh sorry :) It's a public property on the control
private
string
_categoryID = String.Empty;
public
string
CategoryID
get
return
_categoryID;
set
_categoryID = value;
Excellent post, you saved me a ton of time trying to figure this out. I agree, not very FLUENT but works.