Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this query now i try to convert this query in linq

SQL
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 ..

C#
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
Posted
Updated 15-May-16 7:04am
v3

1 solution

I'd have a read of the below, the first has a simple example of using count with group by and the second has a more complex example

linq + C# + group by + count[^]
c# - linq with groupby and count - Stack Overflow[^]
 
Share this answer
 
Comments
super_user 14-May-16 2:36am    
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
group stdtable by new { catg.Catg_type1, prog.Prog_name, yea.year, stdtable.Catg_id } into z
select new
{
Catg_type1 = z.Key.Catg_type1,
Prog_name = z.Key.Prog_name,
year = z.Key.year,
Catg_id = z.Key.Catg_id
}).ToList();

var result = new
{
Total = re.Select(p => p.Catg_id).Distinct().Count()
};
super_user 14-May-16 2:37am    
now how to pass parameter "year_p" in linq?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900