0

Hi all I am having a sql query which I would like to execute the same using entity framework and bind it to gridview can some one help me. This is my query

SELECT Technology,[Description], Technologies.TechID, COUNT(*) AS 'num_employees'
FROM Technologies
LEFT JOIN Questions   
ON Questions.TechID = Technologies.TechID
GROUP BY Technologies.TechID, Technology,[Description]

How can I convert the same to get the results using EF

2 Answers 2

1

Personally, I would make this a stored procedure instead, and import it into EF. Then you would just call it in your code and databind the result to your grid.

This way the joining, grouping, etc all happens server side instead of client side. Otherwise, you'd be sending a lot more information than necessary to the client. Plus, the server can theoretically do these operations faster than a client's.

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

2 Comments

yeah i too just got that idea ;)
Yeah, I usually feel "dirty" when I make a stored procedure that doesn't have any parameters and is just a fairly simple return. I suggest beefing it up with some parameters so you feel better about making it a sproc. :)
0

Try this, i didn't have the time to test it both for logic and syntax. You need something similar.

var q = from a in context.Technologies
    join b in context.Questions
    on a.TechID equal b.TechID into j1
    from j2 in j1.DefaultIfEmpty()
    group j2 by new { a.TechID, b.Technology, b.Description into grouped
    select new { Tecnology = grouped.Technology, Description = grouped.Description, Count = grouped.Count() }

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.