Oracle
 sql >> Baza danych >  >> RDS >> Oracle

Dynamicznie generuj wyrażenie lambda ze stałymi ze zmiennych

Można to zrobić stosunkowo łatwo za pomocą ExpressionVisitor który ocenia ConstantExpression członkowie lubią to:

public static class ExpressionUtils
{
    public static Expression<TDelegate> ReplaceVariablesWithConstants<TDelegate>(this Expression<TDelegate> source)
    {
        return source.Update(
            new ReplaceVariablesWithConstantsVisitor().Visit(source.Body), 
            source.Parameters);
    }

    class ReplaceVariablesWithConstantsVisitor : ExpressionVisitor
    {
        protected override Expression VisitMember(MemberExpression node)
        {
            var expression = Visit(node.Expression);
            if (expression is ConstantExpression)
            {
                var variable = ((ConstantExpression)expression).Value;
                var value = node.Member is FieldInfo ?
                    ((FieldInfo)node.Member).GetValue(variable) :
                    ((PropertyInfo)node.Member).GetValue(variable);
                return Expression.Constant(value, node.Type);
            }
            return node.Update(expression);
        }
    }
}


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. to jest błąd ORA-12154:TNS:nie można rozwiązać podanego identyfikatora połączenia?

  2. Jak działa funkcja HEXTORAW()? Jaki jest algorytm?

  3. Dodawanie typów plików, które mają być rozpoznawane przez Files.probeContentType(new File(.ttf).toPath());

  4. Tydzień pracy SQL w Oracle

  5. Obsługa wartości Null w funkcji Greatest w Oracle