0

I want convert following LINQ query to SQL query.

var ACTIVITY_ROYALITY_MONTH = from m in db.MiningPermit
                                      join pm in db.Permit_Mineral on m.MINING_PERMIT_ID equals pm.MINING_PERMIT_ID
                                      join r in db.Royality on pm.Permit_Minerals_ID equals r.Permit_Minerals_ID
                                      where r.ORDER_ID == 0 // NULL in server
                                      orderby r.YEAR, r.MONTH
                                      group r by new { m.MINING_PERMIT_ID , r.YEAR, r.MONTH }  into mpmr
                                      select mpmr.ToList();
3
  • What have you tried so far? Commented Apr 7, 2020 at 7:41
  • You can view actual query that is being executed. See this to find out how to view SQL query stackoverflow.com/questions/11002573/… Commented Apr 7, 2020 at 7:43
  • 1
    That's a bad LINQ query - LINQ isn't a replacement for SQL and the JOINs are generated by EF or L2S based on the context relations. What it does isn't what it looks like either - there's no way you can use GROUP BY and get any non-group column back without aggregation. What this really does is join some tables and return all rows and columns. You can copy it as-is, put SELECT * at the top and remove the GROUP BY clause Commented Apr 7, 2020 at 7:56

1 Answer 1

3

Use Linqpad and recreate the linq (even by bringing in your assemblies) in a C# query. Run the query. Then in the output, there is a selection button of SQL which will show the sql code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.