NHibernate LINQ Contains 不起作用
我是 NHibernate 的新手,正在与 FluentNhibernate 合作开展一个新项目。在执行一个非常简单的 linq 查询时,我遇到了一个奇怪的问题。
查询 1 - 工作得很好
//Query 1
var customers = from customer in _session.Query<Customer>()
where customer.FirstName == "john"
select new
{
customer.FirstName,
customer.LastName
};
当执行下面的查询 2 时,我收到错误“无法执行查询”
//Query 2.
var customers = from customer in _session.Query<Customer>()
where customer.FirstName.Contains("john")
select new
{
customer.FirstName,
customer.LastName
};
NH 生成的查询是,
选择 customer0_.FirstName 作为 col_0_0_,customer0_.LastName 作为 col_1_0_ 来自 tblCustomer customer0_ 其中 customer0_.FirstName like ('%'||@p0||'%');@p0 = 'john'
它已生成 FirstName like ('%'||@p0||'%') 而不是 FirstName ('%'+@p0+'%') 。
我使用的数据库是SQLServerCE,NHibernate版本是3.1.0
请帮助解决这个问题。
I am new to NHibernate and working with FluentNhibernate for a new project. I came accross a strange issue when executing a very simple linq query.
Query 1 - Works very well
//Query 1
var customers = from customer in _session.Query<Customer>()
where customer.FirstName == "john"
select new
{
customer.FirstName,
customer.LastName
};
When below query 2 is executed I get an error "Could not execute query"
//Query 2.
var customers = from customer in _session.Query<Customer>()
where customer.FirstName.Contains("john")
select new
{
customer.FirstName,
customer.LastName
};
The NH generated query is,
select customer0_.FirstName as col_0_0_, customer0_.LastName as col_1_0_
from tblCustomer customer0_
where customer0_.FirstName like ('%'||@p0||'%');@p0 = 'john'
it has generated FirstName like ('%'||@p0||'%') instead of FirstName like ('%'+@p0+'%') as I can understand.
The database I am using is SQLServerCE and the NHibernate version is 3.1.0
Please help resolving this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是“Dialect.cs”文件(NH 的基本方言类)中 concat 函数的定义:
这应该
用于 SQL CE。
所以你必须使用MsSqlCe40Dialect 类。
我认为它还没有在 Fluent-NHibernate 中注册,所以你可以这样定义它:
另外还有一个针对其余缺失功能的补丁,正在等待批准:
https://nhibernate.jira.com/browse/NH-2723
请投票!
同时,您可以创建自己的方言:
然后您可以通过定义来使用它:
This is the definition of concat function in "Dialect.cs" file (base dialect class of NH):
Which should be
for SQL CE.
So you have to use MsSqlCe40Dialect class.
I think it's not registered in the fluent-NHibernate yet, so you can define it this way:
Also there is a patch for the rest of missing functions, waiting for approval:
https://nhibernate.jira.com/browse/NH-2723
Please vote!
In the meantime you can create your own dialect:
And then you can use it by defining: