This is my model class.
public class Lead
{
private readonly ObservableCollection<String> m_tags = new ObservableCollection<string>();
public int LeadId { get; set; }
public string Title { get; set; }
public ObservableCollec开发者_如何学编程tion<String> Tags { get { return m_tags; } }
}
Does nHibernate offer a way to represent this while maintaining the simple public API of the model?
Not sure if it will work with observable collection (may need to map as IList and handle that behind the scenes) but I think you'd need to do something like this in your mapping:
<class name="Lead" table="Lead">
<!-- snip -->
<set name="Tags" table="Tags">
<key column="TagId" />
<element column="TagValue" type="string" />
</set>
</class>
The only drawback is it does require a keyed table for your tag values.
However, I worry that the same tag can appear on multiple leads. If this is the case, I think you will want to define tags as a many to many with an intermediate table. That would look something like this (requiring an object for your tag):
<class name="Lead" table="Lead">
<!-- snip -->
<set name="Tags" table="LeadsXTags" lazy="false" fetch="select" cascade="save-update">
<key column="LeadId"></key>
<many-to-many class="Tag" column="TagId"></many-to-many>
</set>
</class>
精彩评论