I’m trying to setup a set of data models like so:
[ActiveRecord, JoinedBase]
public class Locale : DataType
{
private int m_id;
private String m_DisplayName;
private String m_Code;
public Locale()
{
}
[PrimaryKey]
public override int Id
{
get { return m_id; }
set { m_id = value; }
}
[Property]
public String DisplayName
{
get { return m_DisplayName; }
set { m_DisplayName = value; }
}
[Property]
public String Code
{
get { return m_Code; }
set { m_Code = value; }
}
}
[ActiveRecord, JoinedBase]
public class LocaleStringInstance : DataType
{
private int m_id;
private String m_text;
public LocaleStringInstance()
{
}
[PrimaryKey]
public override int Id
{
get { return m_id; }
set { m_id = value; }
}
[Property]
public String Text
{
get { return m_text; }
set { m_text = value; }
}
}
[ActiveRecord(Lazy=true), JoinedBase]
public class LocaleString : DataType
{
private int m_id;
private IDictionary<Locale, LocaleStringInstance> m_LocaleStrings;
public LocaleString()
{
}
[PrimaryKey]
public override int Id
{
get { return m_id; }
set { m_id = value; }
}
[HasAndBelongsToMany(typeof(LocaleStringInstance),
RelationType.Map, ColumnRef="LS_Col_Ref", ColumnKey = "LocaleStringInstance_id", Table = "LocaleStringMapping",
RelationType = RelationType.Map, Cascade = ManyRelationCascadeEnum.AllDeleteOrphan,
Lazy = true, Index = "Locale", IndexType= "Locale")]
virtual public IDictionary<Locale, LocaleStringInstance> LocaleStrings
{
get { return m_LocaleStrings; }
set { m_LocaleStrings = value; }
}
}
The main problem lies in trying to model the last property here, “LocaleStrings”.
The idea is that a particular LocaleString will have a string for each ‘locale’ that has been defined. The Dictionary is supposed to represent this.
Unfortunately when I try to register these types with ActiveRecord I get the following error:
ActiveRecordException: {“Could not determine type for: Locale, for columns: NHibernate.Mapping.Column(Locale)”} System.Exception {NHibernate.MappingException}
This is because the “IndexType” is set to “Locale”.. But what should it be set to? I’ve tried adding the full namespace to the beginning of Locale, which didn’t work. I’ve also tried setting to string, and int, which naturally work during registration, but fail when I try to actually use the object because a Locale can’t be converted to a string or integer.
Does anyone know how to use this RelationType.Map and IndexType properly? How can I acheive a model that does what I’m looking for?
Thanks
Josh
Unfortunately it appears that it is not possible to model the described relation using Castle.ActiveRecord at this time as it does not support the required parameters that NHibernate would need to make sense of it.