Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to entity - Call user defined method from query

In my project, i use several linq queries for getting prices list. I need to calculate values based on these prices.

Is it possible to call a user method (who can, ideally, be in the entity class) directly from the linq query, for example, doing like this would be perfect

from foo in Foo
select new {
  price = foo.Price,
  priceclass = foo.GetClassOfPrice()
}

There would be no data access from GetClassOfPrice, just static code based on the price.

Thank's by advance !

like image 382
eka808 Avatar asked Feb 17 '11 13:02

eka808


1 Answers

Linq-To-Entities can call only special type of methods defined in conceptual model (EDMX). These methods are called Model defined functions. So if you define your method this way you will be able to call it. You can also check this blog post.

like image 178
Ladislav Mrnka Avatar answered Nov 15 '22 11:11

Ladislav Mrnka