2017-06-06 3 views
0

私はEntity Frameworkを使い慣れていませんが、SQLのカウントコードはわかりますが、EFのものは何ですか?Entity Frameworkのカウントコードとは何ですか?

select COUNT(*) 
from Factor f 
left join FactorItems FI on f.FactorID=FI.FactorRef 

と、これは私のエンティティコードです:

var CountOfitem = (from FI in context.FactorItems 
        join P in context.tblparts on FI.PartRef equals P.PartsID 
        where (FI.FactorRef == FactorID) 
        select new 
          { 
           gridcount = FI.Rowno 
          } 

は、どのように私は私のselect newに数え得ることができますか?

+0

を。 – BradleyDotNET

+0

親愛なる@BradleyDotNET私はあなたが溢れているAPIは何かを得ることができないのですか?コードは何ですか? –

+0

@AliEshghi Fluent API:https://en.wikipedia.org/wiki/Fluent_interface – Amy

答えて

1

あなたが行うことができます:

var CountOfitem= (from FI in context.FactorItems 
        join P in context.tblparts on FI.PartRef equals P.PartsID 
        where (FI.FactorRef == FactorID) 
        select new 
         { 
          gridcount=FI.Rowno 
         }).Count(); 

は、項目の数を取得します。

0

あなたがFactorItemsの数を取得したい場合は、単に書く:Count` `についてどのように

var count = context.FactorItems.Count() 

または

var count = context.FactorItems.Where(...).Select(...).Count() 
+0

これはFactorItems.FactorRefをFactorIDでフィルタリングしたいという事実を無視します。 – jao

関連する問題