-1
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));

可能?

4

2 に答える 2

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(Id));

この場合context.Find(id)(コンテキストはList<>)は見つかった要素を返しますが、前のコードは次の理由でブール値を返します。Func<vw_UsuarioPerfilAtributo, bool>

于 2012-12-07T14:20:39.013 に答える
0

あなたはPredicatorBuilderクラスをすることができます。これは、ラムダ式のいくつかの拡張メソッドについて有名なクラスです。このリンクを見てください:

http://petemontgomery.wordpress.com/2011/02/10/a-universal-predicatebuilder/

yoruプロジェクトでこのクラスを追加すると、次のようなことができます。

var result = list.Where(x => condition).And(x => condition).Or(x => condition).ToList();
于 2012-12-07T14:13:00.637 に答える