I need equivalent LINQ to SQL query for the query written in access database. Below is the query in access database.
SELECT Table1.ID, Table1.CODE, MIN (Table1.COST)
FROM Table1 GROUP BY Table1.ID, Table1.CODE
In this query I get COST which is minimum to the given repeated CODE
Below query is giving error “Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.”
var ptQ = from i in
(from uh in ptTable
select new
{
uh.ID, uh.CODE, uh.COST
})
group i by new { i.ID, i.CODE }
into g
select new
{
g.Key.ID, g.Key.CODE, g.Min(uh => uh.COST)
};
You need to specify the property name for the
Mincall:The C# compiler will infer a name if the property value is a property or field access (as per ID and CODE), so the above is equivalent to:
Personally I would specify the names everywhere if they’re not idiomatic C# names otherwise: