Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ query, selecting latest value with group by - Unsupported method
    primarykey
    data
    text
    <p>I have this table with fund data values and I want to select the latest values for each fund (FundId). This query is giving me problems though when executed. "Specified method is not supported".</p> <pre><code>var q = from f in ctx.FundDatas group f by f.FundId into g let latestDataItem = g.OrderByDescending(r =&gt; r.DateOfValue).FirstOrDefault() select new { g.Key, LatestDataItem = latestDataItem }; var list = q.ToList(); //Executed and exception is thrown </code></pre> <p>Why wouldn't this order by work? I <strong>don't</strong> want to just get the Key and DateOfValue, if so I would have just skipped the "let" part and made the select like this:</p> <pre><code>select new { g.Key, LatestDateOfValue = g.Max(y=&gt;y.DateOfValue) }; </code></pre> <p>The above works... But I want the whole object of the latest of each fund data items, not just the max date.</p> <p>Here's the inner exception stack trace:</p> <pre><code>[NotSupportedException: Specified method is not supported.] MySql.Data.Entity.SqlGenerator.Visit(DbApplyExpression expression) +28 System.Data.Common.CommandTrees.DbApplyExpression.Accept(DbExpressionVisitor`1 visitor) +25 MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) +35 MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) +21 MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression) +38 System.Data.Common.CommandTrees.DbProjectExpression.Accept(DbExpressionVisitor`1 visitor) +25 MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree) +60 MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) +376 System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) +125 System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) +442 </code></pre> <p>I'm running MySQL with .NET connector 6.5.4.0.</p> <p>Edit: Table definition:</p> <pre><code>FundId int(6), PK DateOfValue date, PK Value double(12,6) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload