2

I have a custom code-first aggregate function:

[DbFunction("CodeFirstDatabaseSchema", "Custom")]
public static int? Custom(this IEnumerable<ModelClass> g, Expression<Func<ModelClass, int>> field) {
    throw new NotSupportedException();
}

I then try to query using the custom function:

DbSet<ModelClass> models = ...;

var query = from a in models
                group a by a.ColumnName into newgroup
                select newgroup.Custom(g => g.ColumnName);

string sql = query.ToString();   // error "the linq expression node type 'lambda' is not supported in linq to entities."

At runtime, I then get the error "The linq expression node type 'lambda' is not supported in linq to entities." The strange thing is if I use "newGroup.Sum(g => g.ColumnName)", the query works as expected. The signature for Sum seems to be almost identical to my custom function so I'm not sure what I'm doing wrong

I can't post the exact code for ModelClass due to confidentiality, but it's just a basic entity class, i.e.:

using System.ComponentModel.DataAnnotations.Schema

[Table("name")]
public class ModelClass {
   public long id {get; set;}
   public string field {get; set;}

   ...
}
trs79
  • 309
  • 3
  • 13

0 Answers0