Dynamic Linq for SQL MIN() function

dynamic-linq linq sql

Question

Original SQL looks like:

SELECT MIN(ID) AS GeoID, MIN(PostalCode), PlaceName
    FROM GeoData_ALL
    GROUP BY CountryCode, PlaceName
    ORDER BY PlaceName

I need to translate it in Dynamic Linq, something like:

var searchResult = db.Set(GeoData)
    .AsQueryable()
    .OrderBy("PlaceName")
    .GroupBy("CountryCode", "PlaceName")
    .Select("new (MIN(ID) AS GeoID, MIN(PostalCode), PlaceName");

Unfortunately 'MIN' function doesn't seem applicable to Dynamic Linq

1
0
4/6/2017 10:38:53 AM

Popular Answer

Following code can help, please check (this is a sample code only):

var searchResult = db.Set(GeoData)
    .AsQueryable()
    .OrderBy("PlaceName")
    .GroupBy("CountryCode", "PlaceName")
    .Select(g => new { GeoID = g.Min(p => p.ID), PostalCode = g.Min(p => p.PostalCode), PlaceName = g.PlaceName });
0
4/6/2017 11:35:34 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow