c# - How to rewrite a method so that it could be executed in LINQ to Entities? -
i have following helper method:
public static double calculatekilospermeter(double diameter, double thickness) { return (diameter - thickness) * thickness * math.pi * 0.008; }
i use when creating instance of model class specific entity.
return pt => new viewablepipetypemodel() { id = pt.id, kilospermeter = logic.calculatekilospermeter(pt.diameter, pt.thickness) };
when execute code above, following exception:
linq entities not recognize method 'double calculatekilospermeter(double, double)' method, , method cannot translated store expression
so, suppose because ef requires expressionfunc.
how can convert method runs under linq entities?
you can obtain anonymous type records first data needed, , use asenumerable()
use regular linq objects.
var objs = ... pt => new { id = pt.id, diam = pt.diameter, thick = pt.thickness }; var res = objs.asenumerable().select(p => new viewablepipetypemodel() { id = p.id, kilospermeter = logic.calculatekilospermeter(p.diam, p.thick) };
Comments
Post a Comment