Fluent Nhibernate引用对象的id,而不是object [英] Fluent Nhibernate reference object by id, and not by object
本文介绍了Fluent Nhibernate引用对象的id,而不是object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,我的实体课如下:
Greetings, my entity class looks like this:
public class Foo
{
public virtual long ID { get; set; }
public virtual string Name { get; set; }
public virtual Foo2 Foo2 { get; set; }
}
和他的映射:
And mapping for him:
public class FooMap: ClassMap<Foo>
{
public FooMap()
{
id(x=>x.ID);
Map(x=>x.Name);
References(x=>x.Foo2).Cascade.All;
}
}
如何将它链接到id,而不是一个对象?
这样的东西:
How can link it to the id, instead of an object?
Something like this:
public class Foo
{
public virtual long ID { get; set; }
public virtual string Name { get; set; }
public virtual long Foo2ID { get; set; }
}
我怎样才能实现这个目标?
How can i achieve this?
推荐答案
然后使用Map(x => x.Foo2ID),但是你失去了级联相关的功能。使用Map(x => x.Foo2ID),您只需告诉NHibernate映射到该列,就好像它就像任何其他列一样。
Just use Map(x=>x.Foo2ID) then, but then you lose the cascade related functionality. Using Map(x=>x.Foo2ID) you just tell NHibernate to map to that column as if it was just like any other column.
这篇关于Fluent Nhibernate引用对象的id,而不是object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文