1

I'm fairly new to using Linq in C# and I just want to know how a normal SQL statement will look like when compared to a Linq query?

I have this statement:

var query =
from b in db.Employee.Include(o => o.Position)
where b.Position.Position_Desc == "Junior" && b.Employee_ID == 5
select b;

So my actual question is how will this statement look if I were to write it in SQL?

1
  • You can execute this code against a real SQL server and use SQL profiler to see the actual SQL query Commented May 5, 2016 at 11:51

3 Answers 3

1

query.ToString() should return the SQL.

Or you can use LinqPad

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

Comments

0

If there is a relation between Employees and Positions tables with foreign key say Employees.PositionId -> Positions.Id. Then you can use LEFT JOIN to write a similar SQL query:

SELECT Employees.*,
       Positions.*
FROM Employees
LEFT JOIN Positions ON Employees.PositionId = Positions.Id
WHERE Positions.Position_Desc = 'Junior'
      AND Employees.Employee_ID = 5

Comments

0

You can check your query in debug mode (see attach image)

enter image description here

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.