Пример #1
0
        public override SqlProvider FormatToList <T>()
        {
            var topNum = DataBaseContext <T>().QuerySet.TopNum;

            if (topNum.HasValue)
            {
                return(FormatToPageList <T>(1, topNum.Value));
            }

            var selectSql = ResolveExpression.ResolveSelect(null);

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            var joinSql = ResolveExpression.ResolveJoinSql(JoinList, ref selectSql);

            var groupSql = ResolveExpression.ResolveGroupBy();

            var havingSql = ResolveExpression.ResolveHaving();

            var orderbySql = ResolveExpression.ResolveOrderBy();

            SqlString = $"{selectSql} {fromTableSql} {joinSql} {whereSql} {groupSql} {havingSql} {orderbySql}";

            return(this);
        }
Пример #2
0
        public override SqlProvider FormatToPageList <T>(int pageIndex, int pageSize)
        {
            var orderbySql = ResolveExpression.ResolveOrderBy();

            var selectSql = ResolveExpression.ResolveSelect(null);

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            var joinSql = ResolveExpression.ResolveJoinSql(JoinList, ref selectSql);

            var groupSql = ResolveExpression.ResolveGroupBy();

            var havingSql = ResolveExpression.ResolveHaving();

            SqlString = $@" SELECT T2.* FROM(
                            SELECT T.*,ROWNUM ROWNUMS FROM (
                            {selectSql}
                            {fromTableSql} {joinSql} {whereSql} {groupSql} {havingSql} {orderbySql}
                            ) T 
                            )T2
                            WHERE ROWNUMS BETWEEN {((pageIndex - 1) * pageSize) + 1} and {pageIndex * pageSize}";
            return(this);
        }
Пример #3
0
        public override SqlProvider FormatGet <T>()
        {
            var selectSql = ResolveExpression.ResolveSelect(null);

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            var joinSql = ResolveExpression.ResolveJoinSql(JoinList, ref selectSql);

            var groupSql = ResolveExpression.ResolveGroupBy();

            var havingSql = ResolveExpression.ResolveHaving();

            var orderbySql = ResolveExpression.ResolveOrderBy();

            SqlString = $@"SELECT T.* FROM( 
                            {selectSql}
                            {fromTableSql} {joinSql}
                            {whereSql}
                            {groupSql}
                            {havingSql}
                            {orderbySql}
                            ) T
                            WHERE ROWNUM<=1";

            return(this);
        }
Пример #4
0
 public override SqlProvider FormatInsert <T>(T entity, string[] excludeFields)
 {
     SqlString = ResolveExpression.ResolveBulkInsert <T>(new List <T> {
         entity
     }, excludeFields);
     return(this);
 }
Пример #5
0
        public override SqlProvider FormatCount()
        {
            var selectSql = "SELECT COUNT(1)";

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            string noneSql = string.Empty;

            //连表字符
            var joinSql = ResolveExpression.ResolveJoinSql(JoinList, ref noneSql);

            if (!Context.Set.IsDistinct)
            {
                SqlString = $"{selectSql} {fromTableSql} {joinSql} {whereSql} ";
            }
            else
            {
                //字段解析字符
                string countBySql = ResolveExpression.ResolveSelect(null);

                SqlString = $@"SELECT COUNT(*) FROM(
                                {countBySql} {fromTableSql}
                                {joinSql}
                                {whereSql}
                                 )T";
            }

            return(this);
        }
Пример #6
0
        public override SqlProvider FormatDelete()
        {
            var fromTableSql = FormatTableName(false, false);

            ProviderOption.IsAsName = false;

            var whereSql = ResolveExpression.ResolveWhereList();

            SqlString = $"DELETE {fromTableSql} {whereSql}";
            return(this);
        }
Пример #7
0
        public override SqlProvider FormatMax(LambdaExpression maxExpression)
        {
            var selectSql = ResolveExpression.ResolveMax(maxExpression);

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            string noneSql = "";
            var    joinSql = ResolveExpression.ResolveJoinSql(JoinList, ref noneSql);

            SqlString = $"{selectSql} {fromTableSql}{joinSql} {whereSql} ";

            return(this);
        }
Пример #8
0
        public override SqlProvider FormatUpdateSelect <T>(Expression <Func <T, T> > updator)
        {
            throw new DapperExtensionException("Oracle不支持修改并查询");

            var update = ResolveExpression.ResolveUpdate(updator);

            var selectSql = ResolveExpression.ResolveSelect(null);

            var fromTableSql = FormatTableName();

            var whereSql = ResolveExpression.ResolveWhereList();

            SqlString = $"UPDATE {FormatTableName(false, false)} {update.SqlCmd} {whereSql}; {selectSql} {fromTableSql} {whereSql};";

            return(this);
        }
Пример #9
0
        public override SqlProvider FormatUpdate <T>(Expression <Func <T, T> > updateExpression)
        {
            var update = ResolveExpression.ResolveUpdate(updateExpression);

            var fromTableSql = FormatTableName(false, false);

            ProviderOption.IsAsName = false;

            var whereSql = ResolveExpression.ResolveWhereList();

            Params.AddDynamicParams(update.Param);

            SqlString = $"UPDATE {fromTableSql} {update.SqlCmd} {whereSql}";

            return(this);
        }
Пример #10
0
        public override SqlProvider FormatUpdate <T>(T entity, string[] excludeFields)
        {
            var update       = ResolveExpression.ResolveUpdates <T>(entity, Params, excludeFields);
            var fromTableSql = FormatTableName(false, false);

            ProviderOption.IsAsName = false;

            var whereSql = ResolveExpression.ResolveWhereList();

            //如果不存在条件,就用主键作为条件
            if (whereSql.Trim().Equals("WHERE 1=1"))
            {
                whereSql += GetIdentityWhere(entity, Params);
            }

            SqlString = $"UPDATE {fromTableSql} {update} {whereSql}";
            return(this);
        }
Пример #11
0
 public override SqlProvider FormatInsert <T>(IEnumerable <T> entitys, string[] excludeFields)
 {
     SqlString = ResolveExpression.ResolveBulkInsert <T>(entitys, excludeFields);
     return(this);
 }