How to get the product count without using lambda expressions?
I have a table products:
product_id
product_n开发者_开发百科ame
prodcut_price
My dbcontext name is abcentity
.
I want to get how many number of products (like products count) along with product_id
,product_name
,product_price
.
I have done using lambda expressions using Groupby product_id
(this is for Linq to Sql, but I am using linq to entity).
I don't want to use lambda expressions. Is it possible to get the product count without using lambda expressions?
Are you just trying to avoid lambda syntax? You can use the group by
clause in LINQ query expression syntax instead of calling .GroupBy()
.
from p in abcentity.products
group p by p.product_id into g
select new {g.Key, g.Count()}
But I should point out that this still gets compiled as a lambda expression. All you're changing is the syntax you use to represent it.
If you're using Linq to SQL by default, then no. The Expression
that is created from making the lambda is what is used to determine the query to create.
If you want a custom expression, you can execute any SQL you define - Scott Gu blogged about how to do this here.
If that is not what you want to do, then perhaps you can explain why you don't want to use lambda expressions?
精彩评论