Fluent Nhibernate - 生成非主键序列生成值
我有一个与此非常相似的实体映射。
public class MyClassMap : ClassMap<MyClass>
{
public MyClassMap()
{
Id(x => x.Id);
Map(x => x.Code);
Map(x => x.Name);
Map(x => x.Description);
}
}
我想知道是否有任何可能的方法可以通过序列自动生成代码字段(不是主键的一部分)。有一个GenerateBy 属性,但它只是IdentityPart 类成员。
I have an entity mapping quite similar to this one.
public class MyClassMap : ClassMap<MyClass>
{
public MyClassMap()
{
Id(x => x.Id);
Map(x => x.Code);
Map(x => x.Name);
Map(x => x.Description);
}
}
I'd like to know if there's any possible way to have the Code field (which is not part of the Primary Key) autogenerated by a sequence. There's a GeneratedBy property, but it's only an IdentityPart class member.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白如何使用监听器使使用内置方法为非 ID 列使用序列生成器变得更加容易。
但是,如果唯一的解决方案是挂钩 OnPreInsert,直接查询数据库和数据库。调用序列并获取它的值,然后我想我将不得不忍受它。
Mauro,这就是你解决问题的方法吗?
编辑:
在 nHibernate & 上发布了问题FluentNHibernate 谷歌组:
https://groups.google.com/group/nhusers/browse_thread/thread/35d37b9abf3566f0
https://groups.google.com/group/ Fluent-nhibernate/browse_thread /线程/35d37b9abf3566f0
I don't see how using Listeners makes it any easier to use a built-in method for using sequence generators for non-ID columns.
However, if the only solution is to hook into OnPreInsert, making a direct query to the DB & invoke the sequence and get its value, then I suppose I'll have to live with it.
Is this how you solved the issue, Mauro?
Edit:
posted the question on the nHibernate & FluentNHibernate google groups:
https://groups.google.com/group/nhusers/browse_thread/thread/35d37b9abf3566f0
https://groups.google.com/group/fluent-nhibernate/browse_thread/thread/35d37b9abf3566f0
您需要使用SaveOrUpdateEventListeners。请参阅此处查看 Jake 的回复,了解如何操作让它为 Fluent 工作。
You need to use
SaveOrUpdateEventListeners
. See here to see Jake's reply for how to get it working for Fluent.