我有一些冗余的主键问题。流利的NHibernate重复列
我有一个项目,其中包含许多报告。我已经如下所示映射它们。我可以做Session.QueryOver(Of Item).List
并且没有生成额外的列。我也可以做Session.QueryOver(Of Report).List
并且没有生成额外的列。
但是,一旦我尝试遍历从Item到Reports的关系,就会得到如下所示的SQL查询。谁能告诉我为什么?提前致谢!
物品映射:
Public Class ItemMapping
Inherits ClassMap(Of Item)
Public Sub New()
Table("Items")
Id(Function(x) x.ItemID)
HasMany(Function(x) x.Reports).KeyColumn("ItemID").Inverse().Cascade.All()
End Sub
End Class
报告映射:
Public Class ReportMapping
Inherits ClassMap(Of Report)
Public Sub New()
Table("Reports")
Id(Function(x) x.ReportID)
References(Function(x) x.Item).Column("ItemID")
Map(Function(x) x.ReportName)
End Sub
End Class
SQL结果:
SELECT repor0_.ItemID as ItemID1_,
repor0_.ReportID as Rep1_1_,
repor0_.ReportID as Rep1_4_0_,
repor0_.ReportName as Rep2_4_0_,
repor0_.ItemID as ItemID4_0_ FROM dbo.Reports repor0_ WHERE [email protected];@p0 = 1266 [Type: Int32 (0)]
非常感谢您提供的信息。为什么它只是偶尔发生?我有其他的关系,不会产生额外的列。这会导致插入/更新查询问题吗?我在这里看到一些帖子,其中映射导致插入/更新失败,因为它正在生成附加列 – Origin
@Origin nhusers组中的线程列出了一些发生时的情况。我在许多项目中一直使用NHibernate,并且我没有遇到过这样的问题(为插入或更新生成额外的列)。我会考虑NHibernate是非常稳定的产品。 –