LINQ to SQL C#中的SELECT COUNT
技术问答
579 人阅读
|
0 人回复
|
2023-09-14
|
如何使用COUNT将LINQ编写为SQL?. C6 z" i# p7 {0 s! @
例子:* o, q* i1 O, ^0 }
var purch = from purchase in myBlaContext.purchases+ g1 d' E. f+ x1 `! A" @
select purchase;
- Q [6 R: p! x( g$ n0 X; [我如何在这里得到计数?* {0 J( R* P8 L6 q+ l
! {- c9 D9 Y6 h2 ^9 t7 G
解决方案:1 G1 M( T4 b0 e v
* }+ k$ B( S; J$ U, a8 j9 W2 F6 x) | z0 M
2 J% e1 z" [, W5 N' E 像那样
5 n, \7 W* E! \+ Pvar purchCount = (from purchase in myBlaContext.purchases select purchase).Count();
" Z, B) T+ s2 p甚至更容易
. H4 X, Q, u" I! u5 X2 hvar purchCount = myBlaContext.purchases.Count() |
|
|
|
|
|