有sum,没有group by的Sql用Linq怎么写

select sum([CardPrice]) as SurplusValue from [CardPassword] where [IsUses]='0' and createdatetime>='2014-5-24'

EF

from t in
                        (from t in context.CardPasswords
                            where
                                t.IsUses == "0" &&
                                t.CreateDateTime >= DateTime.Parse("2014-5-24")
                            select new
                            {
                                t.CardPrice,
                                Dummy = "x"
                            })
                        group t by new {t.Dummy}
                        into g
                        select new
                        {
                            SurplusValue = g.Sum(p => p.CardPrice)
                        };

注意到上面加了个Dumy,用来强制分组的

你可能感兴趣的:(有sum,没有group by的Sql用Linq怎么写)