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

Forums / Developing with Sitefinity / NewsItem Query

NewsItem Query

4 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    17 May 2011
    Link to this post
    Why would this:
    var rotatorCategory = new Guid("8C4DACE0-7867-40E5-B261-E963AB672E4B");
    var content = App.WorkWith().NewsItems()
                                .Publihed()
                                .Where(ci => ci.GetValue<IList>("Category").Contains(rotatorCategory))
                                .Get();
     
    rotator.DataSource = content.ToList();
    rotator.DataBind();

    be throwing this:

    NonGeneric method 'object GetValue(string fieldName)' is not supported in LINQ queries. Use generic 'TValue GetValue<TValue>(string fieldName)' instead.

    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.NotSupportedException: NonGeneric method 'object GetValue(string fieldName)' is not supported in LINQ queries. Use generic 'TValue GetValue<TValue>(string fieldName)' instead.

    Source Error: 

    Line 19:                 .Where(ci => ((IList<Guid>)ci.GetValue("Category")).Contains(rotatorCategory));
    Line 20: 
    Line 21:             rotator.DataSource = content;
    Line 22:             rotator.DataBind();
    Line 23:         }

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 May 2011
    Link to this post
    Hello Steve,

    Categories are stored in the form of a list of Guids. This means that when you access them you should use:
    .Where(ci => ci.GetValue<IList<Guid>>("Category").Contains(rotatorCategory)).Get();

    As the error message states.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 May 2011
    Link to this post
    This is returning strange results....

    I only have 2 news items in this category, but its giving me 4 items back, one is duplicated, the other is blank???

    http://www.screencast.com/t/gasSIJmG
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 May 2011
    Link to this post
    Hi Steve,

    Get the items where c.Status == ContentLifecycleStatus.Live

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered