LINQ中的多个条件语句
问题描述:
在LINQ中可以这样做,这不会;但是编译这是我试图实现的结果。LINQ中的多个条件语句
我知道我可以在union声明之前过滤它,好奇地知道这是否被支持。
var _tickers = (from _position in positions_
where _position.Ticker_PositionQuote.PropertyValue != string.Empty
select _position.Ticker_PositionQuote.PropertyValue)
.Union(
from _position in positions_
where _position.AssetClassLevel2.PropertyValue.ToUpper() == "EQUITY OPTIONS"
and _position.Ticker_PositionUnderlyerQuote.PropertyValue != string.Empty
select _position.Ticker_PositionUnderlyerQuote.PropertyValue);
感谢,
劳尔Dsouza
答
如果我正确理解你的问题,你正在寻找一种方式来实现这种“和”的声明。如果我错了,请纠正我。
要获得
from item in collection
where condition1 "and" condition2
的结果,你可以使用
from item in collection
where condition1 && condition2
或
from item in collection
where condition1
where condition2
第一种方法可能会更快。
如果您只是在寻找这个“和”,这是一个太复杂的代码片段。尝试在未来给最小的例子=) – Jens 2011-06-16 09:06:07