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

Forums / Developing with Sitefinity / ListItem query with Fluent API in multilingual site

ListItem query with Fluent API in multilingual site

4 posts, 0 answered
  1. Ruth
    Ruth avatar
    25 posts
    Registered:
    17 May 2012
    05 Sep 2012
    Link to this post
    Hi

    I have a list who's content is available in 5 languages.

    Due to the built in Sitefinty list control being far from accessible I'm writing my own control, the query to retrieve the items is as follows:

    var listItems = fluentApi.ListItems().
                    Where(li => li.Parent.Title == ListName).
                    Publihed().
                    Get();
     
    This works fine on the English version however I need to get the other language versions depending on which language version of the site is being browsed. It appears as though the AvailableCultures collection should give me this, and thought I could just check against the current culture however when I try this I get an error stating this has not been implemented server side.

    Could you advise on how this can be achieved?

    Thanks


  2. Ruth
    Ruth avatar
    25 posts
    Registered:
    17 May 2012
    05 Sep 2012
    Link to this post
    I've now investigated this further, if I select the list items based on the parent id then it automatically uses the content from the current language. So my query is as show below, ListId is a Guid which is a public property that gets set via the designer.

    var listItems = fluentApi.ListItems().
                    Where(li => li.Parent.Id == ListId).
                    Publihed().
                    Get();

    The problem is I now have to find the relevant Guid in the database. So whilst this has fixed the previous issue it is still not desirable as our client cms user's will not be able to just check the database for the relevant Id.

    Thanks
  3. codicezerouno
    codicezerouno avatar
    21 posts
    Registered:
    02 Feb 2009
    12 May 2014
    Link to this post

    Hi, 

    I'm getting the same problem, but for blogs. Did you find a solution?

    How to query by a localized property?

    Thanks

  4. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    13 May 2014
    Link to this post
    Hi Stefano,

    You can query localized items as follows ( example is for news items ):

    var currentCulture = Thread.CurrentThread.CurrentUICulture.Name;
     
               NewsManager nm = NewsManager.GetManager();
     
               var newsItems = nm.GetNewsItems().Where(d => d.Status == ContentLifecycleStatus.Live).ToList();
               var items = newsItems.Where(d => d.AvailableCultures.Contains(new CultureInfo(currentCulture))).ToList();

    Regards,
    Victor Velev
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered