Func<vw_UsuarioPerfilAtributo, bool> expressionPerfil = Perf =>
foreach(int _key in Keys){
Perf.Id == _key ||
}
(我需要多个OR ||
)
我认为这比
更快 List<vw_UsuarioPerfilAtributo> teste = new List<vw_UsuarioPerfilAtributo>();
teste.add(context.Find(Id));
可能的?
答案 0 :(得分:1)
也许你需要这样的东西:
//use a method because use a foreach in a lambda expression isn't allowed
public bool myFunction(vw_UsuarioPerfilAtributo Perf){
foreach(int _key in Keys){
if(Perf.Id == _key || /*other condition here*/)
return true;
}
return false;
}
和
Func<vw_UsuarioPerfilAtributo, bool> expressionPerfil = Perf => myFunction(Perf);
或者只是:
Func<vw_UsuarioPerfilAtributo, bool> expressionPerfil = Perf => Keys.Any(_key => Perf.Id == _key || /*other condition here*/);
我认为这比
更快teste.add(context.Find(同上));
在这种情况下context.Find(id)
(其中context是List<>
)返回找到的元素,而前一代码返回布尔值,因为Func<vw_UsuarioPerfilAtributo, bool>
答案 1 :(得分:0)
你可以PredicatorBuilder
课程。它是关于lambda表达式的一些扩展方法的着名类。看看这个链接:
http://petemontgomery.wordpress.com/2011/02/10/a-universal-predicatebuilder/
在yoru项目中添加此类后,您可以执行以下操作:
var result = list.Where(x => condition).And(x => condition).Or(x => condition).ToList();