本文介绍了在linq中转换SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个查询现在我尝试在linq中转换此查询
ALTER procedure [dbo]。[spstdinfo]
@ year_p int
as
选择 Catg_type.Catg_type,Program_type.Prog_name,Year_info.year,
COUNT(std_info.catg_id) as total_students 来自 Std_info
inner join Catg_type on Std_info.Catg_id = Catg_type.Catg_id
INNER join Program_type on Std_info.Prog_id = Program_type.Prog_id
inner join Year_info Std_info.year_id = Year_info.year_id
其中 @ year_p = Year_info.year
group by Catg_type,Program_type.Prog_name,Year_info.year
我尝试过:
i试试这个..
var re =( from stdtable in a.Std_info
join catg in a.Catg_type on stdtable.Catg_id equals catg.Catg_id
join prog in a.Program_type on stdtable.Prog_id等于prog.Prog_id
join yea in a.Year_info on stdtable.year_id等于yea.year_id
选择 new {Std_info = stdtable,catg_type = catg,Program_type = prog,Year_info = yea});
现在在sql查询中有计数使用现在怎么样我在linq中使用计数
我是怎么做到的
解决方案
i have this query now i try to convert this query in linq
ALTER procedure [dbo].[spstdinfo] @year_p int as select Catg_type.Catg_type,Program_type.Prog_name ,Year_info.year, COUNT(Std_info.catg_id) as total_students from Std_info inner join Catg_type on Std_info.Catg_id=Catg_type.Catg_id INNER join Program_type on Std_info.Prog_id=Program_type.Prog_id inner join Year_info on Std_info.year_id=Year_info.year_id where @year_p=Year_info.year group by Catg_type,Program_type.Prog_name,Year_info.year
What I have tried:
i try this ..
var re = (from stdtable in a.Std_info join catg in a.Catg_type on stdtable.Catg_id equals catg.Catg_id join prog in a.Program_type on stdtable.Prog_id equals prog.Prog_id join yea in a.Year_info on stdtable.year_id equals yea.year_id select new { Std_info = stdtable, Catg_type = catg,Program_type=prog,Year_info=yea });
now in sql query there is count use now how i use count in linq
how i done this
解决方案
这篇关于在linq中转换SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!