[英]Adding where clause to IEnumerable Select
我的控制器中有以下代码行,用于选择视图中显示的兴趣的 ID(它们在页面下方列出)。
IEnumerable<int> interestIds = viewModel.ExistingInterests.Select(x => x.InterestId);
但是我希望能够在选择部分添加一个 where 子句。 在 ExisitingInterests 中有一个选定的 bool 变量,我只想要那些是真的。
这将使我能够仅将那些已勾选的添加到数据库中。
每个 Discosultan 在评论中:
IEnumerable<int> interestIds = viewModel.ExistingInterests.Where(x => x.selected == true).Select(x => x.InterestId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.