none
LINQ LAMBDA RRS feed

  • Question

  • Can anyone help me on convertig this query to linq lambda expression:

    select  count(distinct a.CampagnListaId), b.Descricao from [dbo].[CampagnLista] a, [dbo].[Regiao] b, [dbo].[Loja] c
    Where a.LojaId=c.LojaId and c.RegiaoId=b.RegiaoId and a.Resultado!=0
    GROUP BY b.RegiaoId, b.Descricao

    Thank you


    J.Luz

    • Moved by Kevin Linq Monday, September 26, 2016 2:28 AM
    Sunday, September 25, 2016 7:17 PM

Answers

  • Hi Biometrics,

    According to your SQL statement, I create a demo as below for your reference.

    var query = from p in db.CampagnListas
                                join l in db.Lojas on p.LojaId equals l.LojaId
                                join r in db.Regiaos on l.RegiaoId equals r.RegiaoId
                                group p by new { r.RegiaoId, r.Descricao } into g
                                select new
                                {
                                    c = g.Select(t=>t.CampagnListaId).Distinct().Count(),
                                    Descricao = g.Key.Descricao
                                };

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Biometrics Monday, September 26, 2016 10:36 AM
    Monday, September 26, 2016 5:23 AM
    Moderator

All replies

  • If you are using an ORM solution like Entity Framework of even Linq-2-SQL, then you should post to the appropriate MSDN forum.
    Sunday, September 25, 2016 7:57 PM
  • Hi  Biometrics :

    Thank you for posting here.

    Since your issue is related to Linq to SQL , I will move your thread to Linq to SQL forum . 

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Here is the link of LINQ forum:https://social.msdn.microsoft.com/Forums/en-US/home?forum=linqtosql

    If you have anything else regarding C# programming , please feel free to let me know . 

    Best Regards,

    Kevin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, September 26, 2016 2:28 AM
  • Hi Biometrics,

    According to your SQL statement, I create a demo as below for your reference.

    var query = from p in db.CampagnListas
                                join l in db.Lojas on p.LojaId equals l.LojaId
                                join r in db.Regiaos on l.RegiaoId equals r.RegiaoId
                                group p by new { r.RegiaoId, r.Descricao } into g
                                select new
                                {
                                    c = g.Select(t=>t.CampagnListaId).Distinct().Count(),
                                    Descricao = g.Key.Descricao
                                };

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Biometrics Monday, September 26, 2016 10:36 AM
    Monday, September 26, 2016 5:23 AM
    Moderator