ListItem query with Fluent API in multilingual site

Posted by Community Admin on 04-Aug-2018 10:36

ListItem query with Fluent API in multilingual site

All Replies

Posted by Community Admin on 05-Sep-2012 00:00

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


Posted by Community Admin on 05-Sep-2012 00:00

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

Posted by Community Admin on 12-May-2014 00:00

Hi, 

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

How to query by a localized property?

Thanks

Posted by Community Admin on 13-May-2014 00:00

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
 

This thread is closed