0

I want to do:

context.Entities.Select(x => new {
   x.Age,
   x.Name,
   Custom = Function(x));

   bool Function(Entitiy e)
   {
       return e.Cust1 || e.Cust2;
   }

Without changing the IQueryable to IEnumerable (ToList/ToArray...). As you can see the properties I want to run the function for are all in Entity, so I was wandering if there was actually a way to do this. for example with expression or some special syntax.

maybe something similar to this:

context.Entities.Select(x => new {
   x.Age,
   x.Name,
   Custom = exp.Compile()(x));

Expression<Func<Entity, bool>> exp = y => y.Cust1 || y.Cust2;

but this way of using compile Func and not Expression loads to memory.

small
  • 223
  • 1
  • 2
  • 6
  • 1
    Look at [this](https://stackoverflow.com/questions/3635418/custom-method-in-linq-to-sql-query) – Jay Nyxed Jan 20 '21 at 18:48
  • Everything you write into this `Select(..)` will get translated to SQL which has no idea about your `Function(Entity)` – mrogal.ski Jan 20 '21 at 18:50
  • Yea I know, but I thought that since all my Cust1 and Cust2 are in the Entity I can use some sort of expression to do this – small Jan 20 '21 at 18:52

0 Answers0