Linq查询与lamba表达式 [英] Linq query with lamba expression

查看:66
本文介绍了Linq查询与lamba表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在创建sql查询我尝试使用lamda表达式将其转换为linq



I create sql query now i try to convert this in linq with lamda expression

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





我尝试过:



i试试这个



What I have tried:

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
        })



此部分。选择(s => new {

Catg_type = s

})
当我写s时
。然后当我尝试调用program_name,catg_type,年份时没有名字



请你帮忙


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

推荐答案

您的linq查询似乎没问题。



问题在于其他地方...



Your linq query seems to be OK.

A problem lies somewhere else...

Quote:

Richard Deeming 16-May-16 8:36 am

你应该可以使用像:

Catg_type = s.yi.pt.catg.Catg_type



Are你说你没有收到Intellisense列表中的任何项目?

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:49 am
super_user 17-May-16 0:49am



yes


yes





如果intellisense停止工作并且没有显示您希望看到的实体名称当您键入[](点)时,您必须检查是否缺少对 System.Linq 的引用(在 System.Data.Linq.dll )。这是常见的原因...



要解决问题,请在每个中添加对 System.Linq 的引用intellisense停止工作的模块。对于ASP.NET页面,您必须添加对 web.config 文件的引用:



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:

<system.web>
    ...
    <pages>
       <namespaces>
         <add namespace="System.Linq" />
       </namespaces>
    </pages>
</system.web>


这篇关于Linq查询与lamba表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆