Binding news items from Fluent?

Posted by Community Admin on 05-Aug-2018 03:47

Binding news items from Fluent?

All Replies

Posted by Community Admin on 25-Mar-2011 00:00

What am I doing wrong here

protected override void CreateChildControls()
        
            base.CreateChildControls();
 
            var newsItems = App.WorkWith().NewsItems()
                                        .Where(x => ((IList<Guid>)x.GetValue("Category")).Contains(new Guid("8C4DACE0-7867-40E5-B261-E963AB672E4B")))
                                        .Publihed()
                                        .Get();
 
            this.Rotator1.DataSource = newsItems;
            this.Rotator1.DataBind();
        


Server Error in '/' Application.

Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MemberExpression'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MemberExpression'.

Source Error:

Line 38: 
Line 39:             this.Rotator1.DataSource = newsItems;
Line 40:             this.Rotator1.DataBind(); 
Line 41:         
Line 42: 

Posted by Community Admin on 25-Mar-2011 00:00



Posted by Community Admin on 25-Mar-2011 00:00

Hi!

Please try this.

.Publihed().Get()
.ToList();

I Think Your rotator need IEnumerable for binding.
I did the similar job and succeeded.Let me know if you get the right answer. 
I am also new to the sitefinity. Try this I hope you will get there.
Regards!

Posted by Community Admin on 26-Mar-2011 00:00

Thanks for the reply :)

No dice though, same error (sadly)

I wish there were easier fluent methods to get categories

var newsItems = App.WorkWith().NewsItems()
                                        .InCategory("Rotator Items")
                                        .Publihed()
                                        .Get();

...I realize the complication though since you can have multiple "Rotator Items" categories (I believe anyway)

Posted by Community Admin on 29-Mar-2011 00:00
Posted by Community Admin on 30-Mar-2011 00:00

HI Again!
Please try the code below in itemtype you should use news item instead of Image.
I used the following code to filter images by their category.
If you still have some prob then let me know.

Thanks!


 private TaxonomyPropertyDescriptor GetPropertyDescriptor(Type itemType, ITaxon taxon)
        
            return TaxonomyManager.GetPropertyDescriptor(itemType, taxon);
        


        private IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
        
            TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
            int? totalCount = 0;
            var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, "Album.Title=\"" + VehicalName + "\" and Status=\"Live\"", string.Empty, 0, 100, ref totalCount);
            return items;
        


        void GetImagesFromTaxon(Taxon objTaxon)
        
            try
            
                var taxonomyManager = TaxonomyManager.GetManager();
                ITaxon taxon = taxonomyManager.GetTaxon(objTaxon.Id);
                string itemTypeName = "Telerik.Sitefinity.Libraries.Model.Image";
                Type itemType = Telerik.Sitefinity.Utilities.TypeConverters.TypeResolutionService.ResolveType(itemTypeName);
                var manager = Telerik.Sitefinity.Data.ManagerBase.GetMappedManager(itemType, "");
                ContentDataProviderBase contentProvider = manager.Provider as ContentDataProviderBase;
                IEnumerable IE = GetItems(taxon, contentProvider, itemType);


                foreach (Telerik.Sitefinity.Libraries.Model.Image CI in IE)
                
                    if (!IsPostBack && drp_Category.Items.FindByValue(objTaxon.Id.ToString()) == null)
                    
                        drp_Category.Items.Add(new ListItem(objTaxon.Title, objTaxon.Id.ToString()));
                    

                    imagesTag +=  CI.MediaUrl + CI.GetThumbnailUrl();
                
            
            catch (Exception ex)
            
                BLL.ErrorLogging("PhotoGallery => " + ex.Message);
            
        

This thread is closed