2021年1月25日星期一

How to perform subquery,group by and aggregate together using lambda or LINQ in C#

I'm trying to perform groupby with aggregate function inside a subquery using lambda expression .I've manage to write the query using SQL but failing to do the same using Lambda expression. How could we write the same query using Lambda or may be LINQ

select     [user_ID], FirstName, LastName, Phone, Fax, EmailAddress   from table1    where [user_id] in       (select [user_id]        from table2 group by [USER_ID]         having (sum(case when isregistered is not null then 1 else 0 end)) = 0      )  

Below is the model representation

public class AccountDetails  {      public string Username { get; set; }      public string FirstName { get; set; }      public string LastName { get; set; }      public string Phone { get; set; }      public string Fax { get; set; }      public string EmailAddress { get; set; }      public bool? IsRegistered { get; set; }      public string User_Id { get; set; }   }  
https://stackoverflow.com/questions/65888973/how-to-perform-subquery-group-by-and-aggregate-together-using-lambda-or-linq-in January 26, 2021 at 12:50AM

没有评论:

发表评论