使用Fluent Nhibernate将字典与基于实体的键映射 [英] Mapping Dictionary with entity based key using Fluent Nhibernate
本文介绍了使用Fluent Nhibernate将字典与基于实体的键映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下NHibernate HBM,它可以按预期工作,但是由于类可能会更改,并且使我想在FNH中进行映射,这使我的代码变得脆弱,但是我尝试了一下,但似乎无法正常工作,特别是如何获得多对多索引:
I have the following NHibernate HBM that works as expected, but it makes my code brittle as the classes may change and I want to do the mapping in FNH, but try as I might, I cannot seem to get it to work, especially how you get the index-many-to-many:
<map name="Permissions" table="PermissionsBySet" cascade="all">
<key column="PermissionSet_id" />
<index-many-to-many class="Picomole.ReadModel.Permission, Picomole.ReadModel" column="PermissionId" />
<element column="PermissionType" type="Picomole.ReadModel.PermissionType, Picomole.ReadModel" not-null="true" />
</map>
给出以下类别:
public class PermissionSet : DomainObject
{
public virtual PermissionSet Defaults { get; set; }
public virtual IDictionary<Permission, PermissionType> Permissions { get; set; }
}
public class Permission : DomainObject
{
public virtual string Controller { get; set; }
public virtual string Action { get; set; }
}
public enum PermissionType
{
None,
Read,
Write,
Grant
}
推荐答案
感谢Firo向我指出正确的方向.我试图做的最后答案是:
Thanks Firo for point me in the right direction. The final answer for what I was attempting to do was:
HasManyToMany(x => x.Permissions)
.AsEntityMap("PermissionId", "PermissionLevel")
.Element("PermissionLevel", x => x.Type<PermissionLevel>())
.Table("PermissionsBySet");
由于某些问题,我在关闭会话连接方面遇到了一个奇怪的错误,我不得不添加:
And because of some issues I was having with a strange error about the session connection being closed, I had to add:
.Fetch.Join()
.Not.LazyLoad()
这篇关于使用Fluent Nhibernate将字典与基于实体的键映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文