Pass lambda expression to another class run C#

Asked

Viewed 75 times

0

Can you pass a lambda expression to a class, and then execute it ? Something like code below.

Giving error in the expression select new

Error: Error 1 Cannot implicitly Convert type 'System.Linq.Iqueryable' to 'System.Linq.Expressions.Lambdaexpression'. An Explicit Conversion exists (are you Missing a cast?) C: Users Nicola Bogar Desktop Software Bogars.Corporativo.Solution Bogars.Corporativo.Application Class1.Cs 22 26 Bogars.Corporativo.Application

public class ClasseFilha : ClasseBse
{
    public ClasseFilha()
    {
        DataContext context = new DataContext();

        expression = from cidade in context.Cidade.AsNoTracking()
                     join estado in context.Estado.AsNoTracking() on cidade.EstadoHandle equals estado.Handle
                     join pais in context.Pais.AsNoTracking() on estado.PaisHandle equals pais.Handle
                     where cidade.Handle == 1
                     select new
                     {
                         Handle = cidade.Handle,
                         Nome = cidade.Nome,
                         Sigla = cidade.Sigla,
                         PaisHandle = pais.Handle,
                         PaisNome = pais.Nome,
                         EstadoHandle = estado.Handle,
                         EstadoNome = estado.Nome
                     };
    }                
}

public class ClasseBse
{
    public LambdaExpression expression;

    public void ExecuteLambadaExpression()
    {
        expression.Compile();
    }

}
  • I do not understand what you want to do, could improve your question?

  • I would like to assemble a Lambda expression, move to a Lambdaexpression property, and when I want to use it I compile that Lambda expression that is created in this property.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.