+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Binding news items from Fluent?

Binding news items from Fluent?

6 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    25 Mar 2011
    Link to this post
    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: 

  2. Waqar
    Waqar avatar
    16 posts
    Registered:
    23 Nov 2010
    25 Mar 2011
    Link to this post


  3. Waqar
    Waqar avatar
    16 posts
    Registered:
    23 Nov 2010
    25 Mar 2011
    Link to this post
    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!
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    26 Mar 2011
    Link to this post
    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)
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
  6. Waqar
    Waqar avatar
    16 posts
    Registered:
    23 Nov 2010
    30 Mar 2011
    Link to this post
    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);
                }
            }
6 posts, 0 answered