2
有谁知道我们如何使用NHibernate中的Fluent Automapping自动映射动态组件?动态组件流畅自动映射
我知道我们可以将常规类映射为组件,但无法弄清楚如何将字典映射为使用流畅自动映射的动态组件。
感谢
有谁知道我们如何使用NHibernate中的Fluent Automapping自动映射动态组件?动态组件流畅自动映射
我知道我们可以将常规类映射为组件,但无法弄清楚如何将字典映射为使用流畅自动映射的动态组件。
感谢
我们使用以下方法成功(与FluentNH 1.2.0.712):
public class SomeClass
{
public int Id { get; set; }
public IDictionary Properties { get; set; }
}
public class SomeClassMapping : ClassMap<SomeClass>
{
public SomeClassMapping()
{
Id(x => x.Id);
// Maps the MyEnum members to separate int columns.
DynamicComponent(x => x.Properties,
c =>
{
foreach (var name in Enum.GetNames(typeof(MyEnum)))
c.Map<int>(name);
});
}
}
在这里,我们已经制定了一些枚举所有成员分隔列,所有的它们是int。现在我的工作,我们使用不同类型的动态列,看起来像这样,而不是一个情景:
// ExtendedProperties contains custom objects with Name and Type members
foreach (var property in ExtendedProperties)
{
var prop = property;
part.Map(prop.Name).CustomType(prop.Type);
}
这也工作得很好。
什么我仍然要弄清楚是如何利用References
而不是Map
用于引用其他类型的都有自己的映射......
UPDATE: 与参考文献的情况是不幸的是更复杂请参阅this Google Groups thread。总之:
// This won't work
foreach (var property in ExtendedProperties)
{
var prop = property;
part.Reference(dict => dict[part.Name]);
}
// This works but is not very dynamic
foreach (var property in ExtendedProperties)
{
var prop = property;
part.Reference<PropertyType>(dict => dict["MyProperty"]);
}
这就是现在。