0

以下の linq クエリの説明でカウントするにはどうすればよいですか?

選択、グループ化などはできますが、カウントできませんか?

plant = (from c in db.CLIENTDETAILS
         join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
         where c.CLIENTNUMBER == clientNumber
         join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
         where i.LOCNUMBER == l.LOCNUMBER
         join p in db.PLANT on i.CODE equals p.CODE      
         select p.DESCRIPTION.Count())

いつもお世話になっております

4

5 に答える 5

3

結果ではなく列でカウントを行っています。カウントを動かしてみてください:

  var plant = (from c in db.CLIENTDETAILS
     join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
     where c.CLIENTNUMBER == clientNumber
     join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
     where i.LOCNUMBER == l.LOCNUMBER
     join p in db.PLANT on i.CODE equals p.CODE      
     select p.DESCRIPTION).Count();

where i.LOCNUMBER == l.LOCNUMBER結合ですでに処理されているので、おそらく取り除くことができるので、クエリは次のようになります。

  var plant = (from c in db.CLIENTDETAILS
     join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
     where c.CLIENTNUMBER == clientNumber
     join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
     join p in db.PLANT on i.CODE equals p.CODE      
     select p.DESCRIPTION).Count();
于 2013-06-24T11:42:38.383 に答える
1

これを試して

plant = (from c in db.CLIENTDETAILS
     join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
     where c.CLIENTNUMBER == clientNumber
     join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
     where i.LOCNUMBER == l.LOCNUMBER
     join p in db.PLANT on i.CODE equals p.CODE      
     select p.DESCRIPTION).Count();
于 2013-06-24T11:42:47.670 に答える
1

Countクエリ結果全体に対して を実行するには、クエリを括弧で囲む必要があります。

plant = (from c in db.CLIENTDETAILS
         join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
         where c.CLIENTNUMBER == clientNumber
         join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
         where i.LOCNUMBER == l.LOCNUMBER
         join p in db.PLANT on i.CODE equals p.CODE      
         select p.DESCRIPTION).Count();
于 2013-06-24T11:42:50.847 に答える
1
var plant = (from c in db.CLIENTDETAILS
     join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
     where c.CLIENTNUMBER == clientNumber
     join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
     where i.LOCNUMBER == l.LOCNUMBER
     join p in db.PLANT on i.CODE equals p.CODE      
     select p.DESCRIPTION).Count()
于 2013-06-24T11:43:11.260 に答える
0
 plant = (from c in db.CLIENTDETAILS
 join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
 where c.CLIENTNUMBER == clientNumber
 join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
 where i.LOCNUMBER == l.LOCNUMBER
 join p in db.PLANT on i.CODE equals p.CODE      
 select p.DESCRIPTION).Count();
于 2013-06-24T12:29:32.390 に答える