2012-05-10 7 views
0

以下の問題は何ですか?Except Extension Methodを使用しているときの問題

var newContextElementCollection = new List<NewContextElements>(); 

var res= from eleCollection in newContextElementCollection 

    where eleCollection.Property.Except(new List<string> { "Password","Some Other Value" }) 

    select eleCollection; 

NewContextElementCollectionクラスは

public class NewContextElements 
{ 
     public string Property { get; set; } 

     public string Value { get; set; } 
} 

Getting error: Error 1 Instance argument: cannot convert from 'string' to 'System.Linq.IQueryable' Error 2 'string' does not contain a definition for 'Except' and the best extension method overload 'System.Linq.Queryable.Except(System.Linq.IQueryable,

System.Collections.Generic.IEnumerable)' has some invalid arguments

答えて

0

Property下のようですが、あなたのExcept句が取り組むことができるものである文字列、ないIEnumerable<string>、です。正しい

var res= from eleCollection in newContextElementCollection 
    where eleCollection.Property != "Password" 
    select eleCollection; 
+0

。実際、除外リストはスカラー項目ではなくコレクションになります。新しいリストのように {"パスワード"、 "その他の値"}これをどう扱う? –

+0

@ user1323981 - http://stackoverflow.com/a/853551/1583 – Oded

+0

表示されている例には、同様のエンティティタイプがあります。私の場合、それはしかし異なっている。そのような場合、適合しません(私はそうだと思います)。 –

0
var excluded = new List<string> { "Password","Some Other Value" }; 
var res = newContextElementCollection.Where(m => !excluded.Contains(m.Property)); 
関連する問題