开发者

Nhibernate linq where clause with boolean value

If I try to add a where clause, containing a lambda filter on a boolean field, to a nhibernate linq query, the filter seems to be ignored:

var result = Session.Linq().Where(x=> x.Approved);

Session开发者_高级运维 is an iSession and Newspaper is a simple object with the fields NewspaperId int, Name - varchar(50) and Approved - bit.

When I run this the following sql is generated:

SELECT this_.NewspaperId as Newspape1_33_0_, this_.Name as Name33_0_, this_.Approved as Approved33_0_, FROM Newspapers this_

it seems to ignore the lambda if it is for a boolean field. It works fine for the name field, ie:

var result = Session.Linq().Where(x=> x.Name == "The Times");

results in: exec sp_executesql N'SELECT this_.NewspaperId as Newspape1_33_0_, this_.Name as Name33_0_, this_.Approved as Approved33_0_ FROM Newspapers this_ WHERE this_.Name = @p0',N'@p0 nvarchar(9)',@p0=N'The Times'

Anybody know why I can't query on a boolean value?

Any help is greatly appreciated I am using NHibernate 2.1 with linq


It's been a while so you've probably got your answer somewhere else a long time ago. But to answer your question: I can't see a reason why this wouldn't work. Actually I've tried it out in both NH2.1.2 and NH3.0.0. It works in both (verified by looking at the query with SQL Profiler). So it would be interesting to see the mapping you used, perhapse there's something wrong there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜