K12 MVC Widget Cultureinfo issue

innovix solutions asked on July 30, 2019 10:27

Hi all,

When we run query to get data from content tree in custom form component class, UI culture (en-GB) is added to query. Our query do not set for culture. MultiDocumentQuery query = DocumentHelper.GetDocuments()

                                   .Path(productPath, PathTypeEnum.Children)

                          .OnCurrentSite()

                          .NestingLevel(1)

                          .Published()

                          .OrderBy("NodeLevel, NodeOrder, NodeName");

We checked with SQL profiler, Culture condition is automatically added to query.

exec sp_executesql N'SELECT * FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON [V].[NodeSKUID] = [S].[SKUID] WHERE [NodeSiteID] = @NodeSiteID AND (([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= @Now) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= @Now)) AND [NodeAliasPath] LIKE @NodeAliasPath AND [NodeLevel] <= @NodeLevel AND [DocumentCulture] = @DocumentCulture) ORDER BY NodeLevel, NodeOrder, NodeName',N'@NodeSiteID int,@Now datetime2(7),@NodeAliasPath nvarchar(11),@NodeLevel int,@DocumentCulture nvarchar(5)',@NodeSiteID=1,@Now='2019-07-30 13:06:50.1921954',@NodeAliasPath=N'/Products/%',@NodeLevel=2,@DocumentCulture=N'en-GB'

We test this query on other MVC widget controller. we use same Query code but different culture is added to Query (en-US)

exec sp_executesql N'SELECT * FROM View_CMS_Tree_Joined AS V WITH (NOLOCK, NOEXPAND) LEFT OUTER JOIN COM_SKU AS S WITH (NOLOCK) ON [V].[NodeSKUID] = [S].[SKUID] WHERE [NodeSiteID] = @NodeSiteID AND (([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= @Now) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= @Now)) AND [NodeAliasPath] LIKE @NodeAliasPath AND [NodeLevel] <= @NodeLevel AND [DocumentCulture] = @DocumentCulture) ORDER BY NodeLevel, NodeOrder, NodeName',N'@NodeSiteID int,@Now datetime2(7),@NodeAliasPath nvarchar(11),@NodeLevel int,@DocumentCulture nvarchar(5)',@NodeSiteID=1,@Now='2019-07-30 13:08:10.0498590',@NodeAliasPath=N'/Products/%',@NodeLevel=2,@DocumentCulture=N'en-US'

We want to get data from content tree with default Culture (en-US) even if we do not set the culture in query.

Can you advise on this?

Correct Answer

Dmitry Bastron answered on July 30, 2019 11:41

Hi,

It's always better to specify the culture explicitly. But in case you need a default item which doesn't exist in your current culture - just use .CombineWithDefaultCulture() method:

var documents = DocumentHelper.GetDocuments()
    .OnCurrentSite()
    .Published()
    .Culture(LocalizationContext.CurrentCulture.CultureCode)
    .CombineWithDefaultCulture();
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.