locked
Convert linq to sql query RRS feed

  • Question

  • User-930352495 posted

    Hi , I struggle to convert a query from linq to sql ,

    my query is:

     from box in _context.MailIteboxStore.Where(x => x.boxId == boxId)
                    .Include(x => x.boxItem).ThenInclude(x => x.boxItemGen)
                    .Include(x => x.boxItem).ThenInclude(x => x.boxItemQ).ThenInclude(x => x.Qualifing)
                    join itm in _context.ItemStore
                                .Include(x => x.occurrence).ThenInclude(x => x.ExternalKey)
                                .Include(x => x.occurrenceType)
                                .Include(x => x.Store) on box.boxItemId equals itm.itmId
                    join c in _context.occurrenceAttribute.Where(x => x.Attribute.Code == "NEW")
                    select new boxItemBoxDetails
                    {
                        boxItem = box.boxItem,
                        ItemStore = itm,
                   }

    I cannot able to render several join and left join to correct sql 

    Can anyone help me?

    Thanks

    Tuesday, April 27, 2021 9:23 PM

Answers

  • User1535942433 posted

    Hi first100,

    I suggest you could LinqPad. The free version will be more than enough. You could prepare a proper data connection so you can execute your LINQ query. At that point click to the "SQL" view, and you will see the generated SQL statements.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2021 2:06 AM

All replies

  • User1358036820 posted

    If you are not sure read up on how to profile EntityFramework which I am assuming you are using.  this will show you the exact sql being sent after LINQ gets converted to SQL.

    Tuesday, April 27, 2021 10:10 PM
  • User1535942433 posted

    Hi first100,

    I suggest you could LinqPad. The free version will be more than enough. You could prepare a proper data connection so you can execute your LINQ query. At that point click to the "SQL" view, and you will see the generated SQL statements.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2021 2:06 AM