Hello David:
SLQ 2005 Express edition
Visual Web Developer 2005 Express Edition
LLBLGenPro 2.0 August 23rd, 2007
involved entities:
CultureEntity
CountryEntity
RegionInCountryEntity
RegionEntity
RegionLocaleEntity
relationships:
CountryEntity 1:m RegionInCountryEntity n:1 RegionEntity 1:m RegionLocaleEntity m:1 CultureEntity
default.aspx has:
LLBLProGenDataSource2 _cultureDS, binded to DropDownList_Culture
LLBLProGenDataSource2 _countryDS, binded to DropDownList_Country
LLBLProGenDataSource2 _regionInCountryDS, binded to DropDownList_RegionInCountry
_regionInCountryDS has as selectparameter the DropDownList_Country, so when a country is selected the child RegionInCountry entities are shown in DropDownList_RegionInCountry
Depending on the selected culture, the RegionInCountry names will be displayed in the correct language, the displayed datafield in DropDownList_RegionInCountry is the property RegionName :
The code for the extended custom property on RegionInCountry :
using System;
using System.Collections.Generic;
using System.Text;
using nr.EntityClasses;
namespace nr.EntityClasses
{
public partial class RegionInCountryEntity
{
//expose the regionname according to the selected culture
public string RegionName
{
get
{
if (this.Region != null)
return this.Region.RegionName;
else
return "<error: No Region found.>"; //this NEVER occurs
}
}
}
}
The code for the extended custom property on RegionInCountry :
using System;
using System.Collections.Generic;
using System.Text;
using nr.EntityClasses;
namespace nr.EntityClasses
{
public partial class RegionEntity
{
//need to store a reference to the culture so the class is 'smart'
public static int CurrentCultureId = -1;
//expose the regionname according to the selected culture
public string RegionName
{
get
{
//If no locales are defined a null reference will be stored!!(asked in LLBLGen forum)
if (this._regionLocale != null)
{
if (RegionEntity.CurrentCultureId != -1)
{
foreach (RegionLocaleEntity regionLocal in this._regionLocale)
{
if (regionLocal.CultureId == RegionEntity.CurrentCultureId)
return regionLocal.RegionLocaleName;
}
}
}
//if no culture is selected, or no matching culture is stored,
//the default is returned
return this.RegionNameDefault;
}
}
}
}
for these extended properties to work in Page_Load the code is:
protected void Page_Load(object sender, EventArgs e)
{
this.DropDownList_Cultures.SelectedIndexChanged += new EventHandler(DropDownList_Cultures_SelectedIndexChanged);
this.DropDownList_Countries.SelectedIndexChanged += new EventHandler(DropDownList_Countries_SelectedIndexChanged);
//page is loaded for the first time
if (!Page.IsPostBack)
{
//CountryEntity objects have to load their related CountryLocale entities
IPrefetchPath2 prefetchPathCountry = new PrefetchPath2((int)EntityType.CountryEntity);
prefetchPathCountry.Add(CountryEntity.PrefetchPathCountryLocale);
this._countriesDS.PrefetchPathToUse = prefetchPathCountry;
//RegionInCountry objects have to load their related Region entities
//and Region entities their related RegionLocaleEntities (for correct culture display)
IPrefetchPath2 prefetchPathRegion = new PrefetchPath2((int)EntityType.RegionInCountryEntity);
prefetchPathRegion.Add(RegionInCountryEntity.PrefetchPathRegion).SubPath.Add(RegionEntity.PrefetchPathRegionLocale);
this._regionInCountryDS.PrefetchPathToUse = prefetchPathRegion;
}
}
Koen