简体   繁体   English

什么是C#Linq等效于VB.Net Linq Group Join和Into关键字?

[英]What is the C# Linq equivalent to VB.Net Linq Group Join and Into keywords?

I am trying to rewrite an old vb.net app in C#. 我正在尝试用C#重写旧的vb.net应用程序。 I have come across this linq code that I need to convert: 我遇到了我需要转换的linq代码:

 (From wn In dtx.WebQueryGroupNames Group Join _
                    wqg In dtx.WebQueryGroups On wn.QueryGroupNameKey Equals wqg.QueryGroupNameKey _
                    Into Group _
                    From p In Group.DefaultIfEmpty() _
                    Select wn _
                    Where Not (From x In dtx.WebQueryGroups Where x.QueryKey = queryKey Select x.QueryGroupNameKey).Contains(wn.QueryGroupNameKey)).Distinct.ToList

What I have so far is: 到目前为止,我有:

 (from wn in dtx.WebQueryGroupNames Group join  
        wqg in dtx.WebQueryGroups on wn.QueryGroupNameKey equals wqg.QueryGroupNameKey 
        Into Group 
        from p in Group.DefaultIfEmpty() 
        select wn 
        where !(from x in dtx.WebQueryGroups where x.QueryKey = queryKey select x.QueryGroupNameKey).Contains(wn.QueryGroupNameKey)).Distinct(); 

I can't seem to find any information on the Group and Into keywords as it translates to C#. 我似乎找不到有关Group和Into关键字的任何信息,因为它转换为C#。 I think I am missing a key point that makes this query make sense. 我认为我缺少使该查询有意义的关键点。

I believe Group Join translates into a plan join with an into clause. 我相信Group Join转化为计划joininto子句。 Try this 尝试这个

 (from wn in dtx.WebQueryGroupNames join  
        wqg in dtx.WebQueryGroups on wn.QueryGroupNameKey equals wqg.QueryGroupNameKey 
        into g
        from p in g.DefaultIfEmpty() 
        select wn 
        where !(from x in dtx.WebQueryGroups where x.QueryKey = queryKey select x.QueryGroupNameKey).Contains(wn.QueryGroupNameKey)).Distinct();

See http://msdn.microsoft.com/en-us/library/bb397905.aspx 请参阅http://msdn.microsoft.com/en-us/library/bb397905.aspx

The term you're looking for is Group By . 您要查找的术语是“ 分组依据”

var queryLastNames =
    from student in students
    group student by student.LastName into newGroup
    orderby newGroup.Key
    select newGroup;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM