Fluent nHibernate 表中没有标识列
如何为没有标识列的表指定流畅的 NHibernate 映射?
我想要这样的东西:
public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap
{
public CustomerNewMap()
{
WithTable("customers_NEW");
Not.LazyLoad();
Not.Id(); // this is invalid...
Map(x => x.Username);
Map(x => x.Company);
}
}
我的意思是数据库中没有定义主键(数据库中没有太多定义)。
How do I specify with fluent NHibernate mapping for a table that doesn't have an identity column?
I want something like this:
public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap
{
public CustomerNewMap()
{
WithTable("customers_NEW");
Not.LazyLoad();
Not.Id(); // this is invalid...
Map(x => x.Username);
Map(x => x.Company);
}
}
I mean no primary key defined in the database (not much defined in the database).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现答案是:
I found the answer to be:
这并没有直接回答问题..但它回答了此处已接受答案的评论中的问题。
我们的 Ledger 上的 SQL 视图也遇到了同样的问题。问题是当
Id
属性不唯一时,NHibernate 会很高兴地重复行。在我们的例子中......我们有将CustomerAccountId
设置为Id
的 Ledger 条目......这在视图中不是唯一的。为了解决这个问题......我映射了一个 CompositeId,它基于我能找到的使该行唯一的任何内容。在我们的例子中,它是
CustomerAccountId
和WeekEnding
的组合:这足以让 NHibernate 不映射重复项。
This doesn't directly answer the question.. but it answers the issue in the comment to the accepted answer here.
We had the same issue with a SQL View over our Ledger. The problem is that NHibernate will happily duplicate rows when the
Id
property isn't unique. In our case.. we had Ledger entries that had theCustomerAccountId
set as theId
.. which wasn't unique within the view.To get around that.. I mapped a CompositeId that was based on whatever I could find that made the row unique. In our case, it was a combination of
CustomerAccountId
andWeekEnding
:This was enough to have NHibernate not map duplicates.
我发现在类似的情况下我必须显式设置列名称。像这样的东西
I found I had to explicitly set a column name in a similar case. Something like