Example #1
0
 /// <summary>
 /// Not In
 /// </summary>
 /// <param name="expression">表达式树</param>
 /// <param name="sqlPack">sql打包对象</param>
 private static void NotIn(MethodCallExpression expression, SqlPack sqlPack)
 {
     SqlBuilderProvider.Where(expression.Arguments[0], sqlPack);
     sqlPack += " NOT IN ";
     SqlBuilderProvider.In(expression.Arguments[1], sqlPack);
 }
Example #2
0
        /// <summary>
        /// Contains
        /// </summary>
        /// <param name="expression">表达式树</param>
        /// <param name="sqlPack">sql打包对象</param>
        private static void Contains(MethodCallExpression expression, SqlPack sqlPack)
        {
            if (expression.Object != null)
            {
                if (typeof(IList).IsAssignableFrom(expression.Object.Type))
                {
                    SqlBuilderProvider.Where(expression.Arguments[0], sqlPack);
                    sqlPack += " IN ";
                    SqlBuilderProvider.In(expression.Object, sqlPack);
                }
                else
                {
                    SqlBuilderProvider.Where(expression.Object, sqlPack);
                    switch (sqlPack.DatabaseType)
                    {
                    case DatabaseType.SQLServer:
                        sqlPack += " LIKE '%' + ";
                        break;

                    case DatabaseType.MySQL:
                    case DatabaseType.PostgreSQL:
                        sqlPack += " LIKE CONCAT('%',";
                        break;

                    case DatabaseType.Oracle:
                    case DatabaseType.SQLite:
                        sqlPack += " LIKE '%' || ";
                        break;

                    default:
                        break;
                    }
                    SqlBuilderProvider.Where(expression.Arguments[0], sqlPack);
                    switch (sqlPack.DatabaseType)
                    {
                    case DatabaseType.SQLServer:
                        sqlPack += " + '%'";
                        break;

                    case DatabaseType.MySQL:
                    case DatabaseType.PostgreSQL:
                        sqlPack += ",'%')";
                        break;

                    case DatabaseType.Oracle:
                    case DatabaseType.SQLite:
                        sqlPack += " || '%'";
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (expression.Arguments.Count > 1 && expression.Arguments[1] is MemberExpression memberExpression)
            {
                SqlBuilderProvider.Where(memberExpression, sqlPack);
                sqlPack += " IN ";
                SqlBuilderProvider.In(expression.Arguments[0], sqlPack);
            }
        }