Пример #1
0
        public static void RegisterGenericCapabilities(this IConfiguration config)
        {
            config.RegisterMethodSubstitution((ICollection <int> c, int item) => c.Contains(item), (ICollection <int> c, int i) => Operators.IN(i, c));
            config.RegisterMethodSubstitution((IEnumerable <int> c, int item) => c.Contains(item), (IEnumerable <int> c, int i) => Operators.IN(i, c));
            config.RegisterMethodSubstitution((IEnumerable <int> c) => c.Any(), (IEnumerable <int> c) => Operators.EXISTS(c));

            config.RegisterMethodSubstitution((Object s1, Object s2) => String.Concat(s1, s2),
                                              (Object s1, Object s2) => ScalarFunctions.CONCAT((String)s1, (String)s2));
            config.RegisterMethodSubstitution((Object s1, Object s2, Object s3) => String.Concat(s1, s2, s3),
                                              (Object s1, Object s2, Object s3) => ScalarFunctions.CONCAT((String)s1, (String)s2, (String)s3));
            config.RegisterMethodSubstitution((Object s1, Object s2, Object s3, Object s4) => String.Concat(s1, s2, s3, s4),
                                              (Object s1, Object s2, Object s3, Object s4) => ScalarFunctions.CONCAT((String)s1, (String)s2, (String)s3, (String)s4));
            config.RegisterMethodSubstitution((Object s1, Object s2, Object s3, Object s4, Object s5) => String.Concat(s1, s2, s3, s4, s5),
                                              (Object s1, Object s2, Object s3, Object s4, Object s5) =>
                                              ScalarFunctions.CONCAT((String)s1, (String)s2, (String)s3, (String)s4, (String)s5));

            config.RegisterMethodSubstitution((string s1) => s1.ToLower(), (string s1) => ScalarFunctions.LOWER(s1));
            config.RegisterMethodSubstitution((string s1) => s1.ToLowerInvariant(), (string s1) => ScalarFunctions.LOWER(s1));
            config.RegisterMethodSubstitution((string s1) => s1.ToUpper(), (string s1) => ScalarFunctions.UPPER(s1));
            config.RegisterMethodSubstitution((string s1) => s1.ToUpperInvariant(), (string s1) => ScalarFunctions.UPPER(s1));

            config.RegisterMethodSubstitution((string s1, string s2, string s3) => s1.Replace(s2, s3),
                                              (string s1, string s2, string s3) => ScalarFunctions.REPLACE(s1, s2, s3));

            config.RegisterMethodSubstitution((string s1) => s1.Trim(), (string s1) => ScalarFunctions.TRIM(s1));
            config.RegisterMethodSubstitution((string s1) => s1.TrimEnd(), (string s1) => ScalarFunctions.RTRIM(s1));
            config.RegisterMethodSubstitution((string s1) => s1.TrimStart(), (string s1) => ScalarFunctions.LTRIM(s1));
            config.RegisterMethodSubstitution((string s1, string s2) => s1.Contains(s2), (string s1, string s2) => Operators.LIKE(s1, '%' + s2 + '%'));
            config.RegisterMethodSubstitution((string s1, string s2) => s1.StartsWith(s2), (string s1, string s2) => Operators.LIKE(s1, s2 + '%'));
            config.RegisterMethodSubstitution((string s1, string s2) => s1.EndsWith(s2), (string s1, string s2) => Operators.LIKE(s1, '%' + s2));
        }
Пример #2
0
 public T Cast <TExpression>(TExpression?expression)
     where TExpression : struct, IComparable <TExpression> =>
 ScalarFunctions.CAST <T, DataType <T>, TExpression>(expression, this);