I have a domain class with a property IList<string>
that I want to map to a table with a single data value (i.e. it has an ID, a foreign key ID to the domain entity table, and a varchar data column).
I keep getting the error:
Association references unmapped class: System.String
How can I map a table to a collection of strings?
nhibernate Mappings Xml Mappings It is a syntax xml file which contains the metadata required for the object/relational mapping. The metadata includes declaration of persistent classes and the mapping of properties (to columns and foreign key relationships to other entities) to database tables.
I just ran into a similar situation; and I found that it is indeed possible to map a collection of strings. Note that you'll have to map those strings as value objects.
This is what I have:
public class Chapter
{
private ISet<string> _synonyms = new HashedSet<string>();
public ReadOnlyCollection<string> Synonyms
{
get { return new List<string>(_synonyms).AsReadOnly(); }
}
}
Mapping:
<class name="Chapter" table="Chapter">
<set name="Synonyms" table="ChapterSynonyms">
<key column="ChapterId" />
<element column="ChapterCode" type="string" />
</set>
</class>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With