在lambda EX pressions多个Where子句子句、多个、EX、lambda

2023-09-04 01:35:25 作者:迹

我有一个简单的lambda EX pression的是这样的:

I have a simple lambda expression that goes something like this:

x=> x.Lists.Include(l => l.Title).Where(l=>l.Title != String.Empty)

现在,如果我想增加一个where子句前pression,比方说, l.InternalName!=的String.Empty 那么会是什么恩pression是什么?

Now, if I want to add one more where clause to the expression, say, l.InternalName != String.Empty then what would the expression be?

推荐答案

x=> x.Lists.Include(l => l.Title)
     .Where(l => l.Title != String.Empty && l.InternalName != String.Empty)

x=> x.Lists.Include(l => l.Title)
     .Where(l => l.Title != String.Empty)
     .Where(l => l.InternalName != String.Empty)

当你看其中,实现,你可以看到它接受 Func键(T,布尔);这意味着:

When do you look at Where implementation, you can see it accepts a Func(T, bool); that means:

T 是IEnumerable的类型 布尔意味着它需要返回一个布尔值 T is your IEnumerable type bool means it needs to return a boolean value

所以,当你

.Where(l => l.InternalName != String.Empty)
//     ^                   ^---------- boolean part
//     |------------------------------ "T" part
 
精彩推荐
图片推荐