Click here to Skip to main content
15,947,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create sql query now i try to convert this in linq with lamda expression

SQL
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 query=a.Std_info
    .Join(
        a.Catg_type,
        catg=>catg.Catg_id,
        std=>std.Catg_id,
        (catg,std)=>new{catg=catg,std=std})
    .Join(
        a.Program_type,
        pg=>pg.catg.Prog_id,
        pt=>pt.Prog_id,
        (pg,pt)=>new{pg=pg,pt=pt})
    .Join(
        a.Year_info,
        yr=>yr.pg.catg.year_id,
        yi=>yi.year_id,
        (yr,yi)=>new{yr=yr,yi=yi})
    .Select(
        s=>new{
            Catg_type=s
        })

in this part .Select(s=>new{
Catg_type=s
})
when i write s. and then when i try to call program_name,catg_type,year then there is no names

will you please help
Posted
Updated 16-Aug-16 2:18am
v3
Comments
OriginalGriff 16-May-16 1:59am    
"i think not correct" doesn't help us - it tells us nothing about what problem you are experiencing.
Tell us what happened: what did it do that you didn't expect, or not do that you did? What does your input data look like, and what is the result of the two queries?
Were there any messages? Errors? Crashes?

Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
super_user 16-May-16 2:09am    
ok now i try this
var query=a.Std_info
.Join(a.Catg_type,catg=>catg.Catg_id,std=>std.Catg_id,(catg,std)=>new{catg=catg,std=std})
.Join(a.Program_type,pg=>pg.catg.Prog_id,pt=>pt.Prog_id,(pg,pt)=>new{pg=pg,pt=pt})
.Join(a.Year_info,yr=>yr.pg.catg.year_id,yi=>yi.year_id,(yr,yi)=>new{yr=yr,yi=yi})
.Select(s=>new{
Catg_type=s
})
super_user 16-May-16 2:10am    
i this part .Select(s=>new{
Catg_type=s
})

how i call this Catg_type.Catg_type,Program_type.Prog_name ,Year_info.year,
Richard Deeming 16-May-16 8:36am    
You should be able to use something like:
Catg_type = s.yi.pt.catg.Catg_type

Are you saying you're not getting any items in the Intellisense list?
super_user 17-May-16 0:49am    
yes

1 solution

Your linq query seems to be OK.

A problem lies somewhere else...

Quote:
Richard Deeming 16-May-16 8:36am
You should be able to use something like:
Catg_type = s.yi.pt.catg.Catg_type

Are you saying you're not getting any items in the Intellisense list?
super_user 17-May-16 0:49am

yes


If intellisense stopped working and does not display the name of entity you expect to see when you type [.] (dot), you have to check for missing reference to System.Linq (in System.Data.Linq.dll). This is the common reason...

To resolve issue, add a reference to System.Linq in each module where intellisense stopped working. For ASP.NET pages, you have to add reference to web.config file:
XML
<system.web>
    ...
    <pages>
       <namespaces>
         <add namespace="System.Linq" />
       </namespaces>
    </pages>
</system.web>
 
Share this answer
 

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