A
A
addd2015-11-16 10:48:25
SQL
addd, 2015-11-16 10:48:25

How to convert Sql query to EntityFramework?

SET @SQL_A = 'SELECT dbo.Nav.L AS p1,p2,Count(p3) AS Count FROM dbo.Nav with(nolock)
WHERE ' + @Link + ' ' + @Filter + '
GROUP BY dbo.Nav.Link ,Nav.Vendor ORDER BY Nav.Vendor'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2015-11-16
@addd

Something like this (written from memory without a studio):

var paramLink = …;
var paramFilter = …;
var result Nav.Where(nav => nav.Link == paramLink && nav.Filter == paramFilter)
    .GroupBy(nav => new {Link = nav.Link,Vendor = nav.Vendor} , nav => nav)
    .OrderBy(grNav => grNav.Key.Vendor).Select(grNav => new {Link = grNav.Key.Link, Vendor = grNav.Key.Vendor, Count = grNav.Count()});

Instead of the anonymous class new {Link = nav.Link,Vendor = nav.Vendor}, it might be better to use something like KeyValuePair or another class that compares object attributes to establish equality between objects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question