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

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -