2012-12-22 24 views
6

私のSQLコードは次のとおりです。LINQ同等のSQLクエリは

select UserId,UserName 
from aspnet_Users 
where UserId not in (select UsersId from tbluser where active='true') 

同等のLINQ表現が何でありますか?

+0

LiNQを使用して、私の最初の試みが!.Contains()または.Exceptは、()I「は2つの方法があり'VB'または' C# 'に – dougajmcdonald

+1

を認識していますか? –

答えて

10

C#

var result = from y in aspnet_Users 
      where !(
         from x in tblUser 
         where x.active == "true" 
         select x.UsersID 
        ).Contains(y.UserId) 
      select y;     
      -- OR // select new { y.UserId, y.UserName}; 

SOURCE

+0

私はそれが 'x.active'だと思います –

+0

@Sahuaginうん、ありがとう。 –

+1

+1。 –

0
var query = 
    from c in aspnet_Users 
    where !(from o in tbluser where o.active=="true" 
      select o.UserId) 
      .Contains(c.UserId) 
    select c; 
+0

あなたの**コピー**は@JWの回答とどう違うのですか? –

+0

私は@jwの回答を見ていない、私の答えを投稿した後、私は両方が同じであることを知りに来た。 – LNRao

+0

'!aspnet_Users.Any(p => p.active ==" true ")'は同じようには見えません。私はここに何かを逃していますか –