本文介绍了流利的NHibernate IDictionary,带有复合元素映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这两个班级:
public class Category
{
IDictionary<string, CategoryResorce> _resources;
}
public class CategoryResource
{
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
这是xml映射
<class name="Category" table="Categories">
<id name="ID">
<generator class="identity"/>
</id>
<map name="Resources" table="CategoriesResources" lazy="false">
<key column="EntityID" />
<index column="LangCode" type="string"/>
<composite-element class="Aca3.Models.Resources.CategoryResource">
<property name="Name" column="Name" />
<property name="Description" column="Description"/>
</composite-element>
</map>
</class>
,我想用Fluent编写它.我发现了类似的内容,并且正在尝试使用以下代码:
and i'd like to write it with Fluent.I found something similar and i was trying with this code:
HasMany(x => x.Resources)
.AsMap<string>("LangCode")
.AsIndexedCollection<string>("LangCode", c => c.GetIndexMapping())
.Cascade.All()
.KeyColumn("EntityID");
但是我不知道如何将CategoryResource实体映射为Category元素内的复合元素.
but i dont know how to map the CategoryResource entity as a composite element inside the Category element.
有什么建议吗?
谢谢
推荐答案
我认为您要查找的映射是这样的:
I think the mapping you're looking for is something like this:
HasMany<CategoryResource>(x => x._resources)
.AsMap<string>("LangCode")
.KeyColumn("EntityID")
.Table("CategoryResources")
.Component(x =>
{
x.Map(c => c.Name);
x.Map(c => c.Description);
})
.Cascade.All();
这篇关于流利的NHibernate IDictionary,带有复合元素映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!