升级到NHibernate 3.1:LINQ,Any和映射组件集合的错误 [英] Upgrading to NHibernate 3.1: Bug with LINQ, Any and mapped component collections
问题描述
我们当前正在从NHibernate 2升级到3.1.以下方案适用于旧的LINQ提供程序,但不适用于NHibernate 3.1中的新提供程序.
We are currently upgrading from NHibernate 2 to 3.1. The following scenario worked with the old LINQ provider but doesn't work with the new provider in NHibernate 3.1.
这是场景的映射:
public class FooDbMap : ClassMap<Foo>
{
public FooDbMap()
{
Id(x => x.Id);
HasMany(x => x.Bars)
.Component(part =>
{
part.Map(y => y.Name);
})
.KeyColumn("FooId")
.Table("FooBars");
}
}
NHibernate从上面的映射正确生成了模式:
NHibernate correctly generates the schema from the above mapping:
create table Foo (
Id UNIQUEIDENTIFIER not null
)
create table FooBars (
FooId UNIQUEIDENTIFIER not null,
Name TEXT not null,
primary key (FooId, Name)
)
但是,以下查询会产生错误:
However, the following query generates an error:
Session.Query<Foo>()
.Where(foo => foo.Bars.Any())
.ToList();
错误是: System.Data.SqlClient.SqlException:无效的列名"Id".
NHibernate生成的SQL是:
The SQL that NHibernate has generated is:
select foo0_.Id as Id20_
from Foo foo0_
where exists (select bar1_.Id from Bar bar1_
where foo0_.Id = bar1_.FooId)
几乎正确,但不完全正确-NHibernate在最后一分钟弄错了,并决定在Bar表上应该有一个Id列.
Almost right, but not quite - at the last minute NHibernate gets it wrong and decides that there should be an Id column on the Bar table.
以前的Linq-to-Nhibernate提供程序以前不会发生此问题.
This problem didn't used to occur with the old Linq-to-Nhibernate provider.
我可以想到一些解决方法,但这是NHibernate的错误或功能吗?
I can think of a few workarounds, but is this an NHibernate bug or feature?
推荐答案
这是一个错误.您可以在此处投票: NH-2692
It's a bug. You can vote here: NH-2692
这篇关于升级到NHibernate 3.1:LINQ,Any和映射组件集合的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!