Linq to entity - calling a custom method from a request

In my project, I use several linq queries to get a list of prices. I need to calculate values ​​based on these prices.

Is it possible to call a user-defined method (which, ideally, can be in an entity class) directly from a linq query, for example, to do this would be ideal.

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

There will be no access to data from GetClassOfPrice, only static code based on price.

Thanks in advance!

+3
source share
4 answers

Linq-To-Entities , (EDMX). . , , . .

+5

LINQ to Objects, SQL. - - , .

var foos = context.Foo.ToList()
                      .Select( f => new
                       {
                            price = f.Price,
                            priceClass = f.GetClassOfPrice()
                       } );

, ToList (Where), , . , , ToList . LINQ .

+3

, , LINQ SQL. , .

+1

Source: https://habr.com/ru/post/1792799/


All Articles