简体   繁体   English

nhibernate.linq简单(哑巴)问题

[英]nhibernate.linq simple (read dumb) question

I'm trying to wrap my head around linq -> nhib 我想把头缠在linq-> nhib上

I have a simple bit of sql that i'm trying to get working in nhibernate.linq 我正在尝试在nhibernate.linq中工作的一小段SQL

 select * from 
 ColModel where ColModel.DataIndex 
 not in ('CostElement1', 'CostElement2', 'CostElement3')
 and ColModel.ReportId = 1

The list of excluded DataIndex values comes in in the form of a List<string> called excludeNames 排除的DataIndex值的List<string>List<string>的形式出现,称为excludeNames

Here is what I have tried but it seems that it's not really feeling the love: 这是我尝试过的方法,但似乎并没有真正感受到爱:

var s = base._sessionManager.OpenSession();

var query = from col in s.Linq<ColModel>()
            where col.Report.Id == reportid &&
            !(from c in s.Linq<ColModel>() select c.DataIndex).Contains(excludeNames)
            select col;

return query.ToList();

the error: 错误:

The type arguments for method 'System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly. 

I'm pretty sure I'm borfing this from the offset so any pointers would be well appreciated :) 我很确定我正在从偏移量中烦恼,所以任何指针都将受到赞赏:)

w:// w://

I think you have your exclusion backwards. 我认为您的排斥性倒退了。

s = base._sessionManager.OpenSession();

var query = from col in s.Linq<ColModel>()
            where col.Report.Id == reportid &&
                  !excludeNames.Contains(col.DataIndex)
            select col;

return query.ToList();

Collection.Contains(item) will produce the SQL item in (...collection...) , adding the negation will get you what you want. Collection.Contains(item)将item in (...collection...)生成SQL item in (...collection...) ,加上否定即可获得所需的内容。

Contains doesn't accept a list. 包含不接受列表。

There are ways to work around this in LINQ, but I'm not sure which, if any, of those will work in NH Linq 在LINQ中有多种方法可以解决此问题,但是我不确定其中哪些(如果有的话)是否可以在NH Linq中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM