LINQ to SQL C#中的SELECT COUNT
技术问答
530 人阅读
|
0 人回复
|
2023-09-14
|
如何使用COUNT将LINQ编写为SQL?
/ d4 m+ ~" J+ E1 {6 d& z" R* w4 }$ d例子:- Q3 y" S1 B$ G" _- M
var purch = from purchase in myBlaContext.purchases
5 T5 ~+ G: x5 W% X) R8 ~ select purchase;
1 @. Y6 O' W7 m" @! F9 |' A我如何在这里得到计数?. u" h1 ? Y Y* ]! H$ _1 v
. ^3 U1 L& F( y( V7 s; G
解决方案:
0 s( E0 @8 f O) s* y# L/ g
: Q8 B7 d2 e- R. R$ W
: X; q5 f0 Q% K* z: o# ~3 J( ~" S2 Z- o8 E, I5 i& C
像那样* C5 t# A3 W& V& I- G5 Z' D7 q
var purchCount = (from purchase in myBlaContext.purchases select purchase).Count();
5 i) x. w% B, {甚至更容易9 h+ U$ ^$ o o8 v1 s4 M& c1 Y
var purchCount = myBlaContext.purchases.Count() |
|
|
|
|
|