This post has been migrated from www.experimentsincode.com, we apologise if some of the images or content is missing
public class SqlServerDataProvider : Sitecore.Data.SqlServer.SqlServerDataProvider { public SqlServerDataProvider(string connectionString) : base(connectionString) { } protected override void LoadItemFields(string itemCondition, string fieldCondition, object[] parameters, Sitecore.Collections.SafeDictionary<ID, Sitecore.Data.DataProviders.PrefetchData> prefetchData) { base.LoadItemFields(itemCondition, fieldCondition, parameters, prefetchData); //set the default language to use Language defaultLang; Language.TryParse("en", out defaultLang); //full list of languages the site uses LanguageCollection coll = this.GetLanguages(); foreach (var data in prefetchData) { if (data.Value != null) { var uris = data.Value.GetVersionUris(); //check the item contains the default language before doing anything if (uris.Cast<VersionUri>().Any(x => x.Language == defaultLang)) { //get the default language fields var defaultUri = uris.Cast<VersionUri>().First(x => x.Language == defaultLang); //loop through each language foreach (Language lang in coll) { //check if language doesn't exist if (!uris.Cast<VersionUri>().Any(x => x.Language == lang)) { //update language with default language values FieldList fields = data.Value.GetFieldList("en", defaultUri.Version.Number); foreach (var field in fields) { data.Value.AddField(lang.Name, 1, field.Key, field.Value); } } } } } } } }Now that we have our code we need to update the web.config to use our new class. First we need to add our class as a new provider. Find the following section in the Sitecore section of the web.config.
<!-- DATA PROVIDERS --> <dataProviders> <main type="Sitecore.Data.$(database).$(database)DataProvider, Sitecore.$(database)">--> <param ref="connections/$(1)" /> <Name>$(1)</Name> </main>Update it as shown below so that you now have two providers:
<dataProviders> <main type="Sitecore.Data.$(database).$(database)DataProvider, Sitecore.$(database)">--> <param ref="connections/$(1)" /> <Name>$(1)</Name> </main> <web type="Demo.Data.SqlServerDataProvider, Demo"> <param ref="connections/$(1)" /> <Name>$(1)</Name> </web>We then just need to update the relevant databases to use this class. I am assuming that only the web database will use this class. In which case find the following section in the web.config:
<database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel"> <param desc="name">$(id)</param> <securityEnabled>true</securityEnabled> <dataProviders hint="list:AddDataProvider"> <dataProvider ref="dataProviders/main" param1="$(id)">Update the providers list to look like this:
<database id="web" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel"> <param desc="name">$(id)</param> <securityEnabled>true</securityEnabled> <dataProviders hint="list:AddDataProvider"> <dataProvider ref="dataProviders/web" param1="$(id)">