Esempio n. 1
0
 private string ResolveColumns()
 {
     if (_selectExpression == null)
     {
         var filters = new GroupExpressionResovle(_filterExpression).Resovle().Split(',');
         var columns = TableInfoCache.GetColumns(typeof(T))
                       .Where(a => !filters.Contains(a.ColumnName))
                       .Select(s => s.ColumnName != s.PropertyName ? $"{s.ColumnName} AS {s.PropertyName}" : s.PropertyName);
         return(string.Join(",", columns));
     }
     else
     {
         return(new SelectExpressionResovle(_selectExpression).Resovle());
     }
 }
Esempio n. 2
0
        private string ResovleInsert(bool identity)
        {
            var table      = TableInfoCache.GetTable(typeof(T)).Name;
            var filters    = new GroupExpressionResovle(_filterExpression).Resovle().Split(',');
            var columns    = TableInfoCache.GetColumns(typeof(T));
            var intcolumns = columns
                             .Where(a => !filters.Contains(a.ColumnName))
                             .Where(a => !a.IsIdentity);
            var intcolumnNames      = string.Join(",", intcolumns.Select(s => s.ColumnName));
            var intcolumnParameters = string.Join(",", intcolumns.Select(s => $"@{s.PropertyName}"));
            var sql = $"INSERT INTO {table}({intcolumnNames}) VALUES ({intcolumnParameters})";

            if (identity)
            {
                sql = $"{sql};SELECT @@IDENTITY";
            }
            return(sql);
        }
Esempio n. 3
0
        private string ResolveUpdate()
        {
            var table   = TableInfoCache.GetTable(typeof(T)).Name;
            var builder = new StringBuilder();

            if (_setExpressions.Count > 0)
            {
                var where = ResolveWhere();
                foreach (var item in _setExpressions)
                {
                    var column     = new BooleanExpressionResovle(item.Column).Resovle();
                    var expression = new BooleanExpressionResovle(item.Expression, _parameters).Resovle();
                    builder.Append($"{column} = {expression},");
                }
                var sql = $"UPDATE {table} SET {builder.ToString().Trim(',')}{where}";
                return(sql);
            }
            else
            {
                var filters = new GroupExpressionResovle(_filterExpression).Resovle().Split(',');
                var where = ResolveWhere();
                var columns    = TableInfoCache.GetColumns(typeof(T));
                var updcolumns = columns
                                 .Where(a => !a.IsIdentity && a.Key != Attributes.ColumnKey.Primary)
                                 .Where(a => !filters.Contains(a.ColumnName))
                                 .Select(s => $"{s.ColumnName} = @{s.PropertyName}");
                if (string.IsNullOrEmpty(where))
                {
                    var key = (columns.Where(a => a.Key == Attributes.ColumnKey.Primary).FirstOrDefault()
                               ?? columns.First());
                    where = $" WHERE {key.ColumnName} = @{key.PropertyName}";
                }
                var sql = $"UPDATE {table} SET {string.Join(",", updcolumns)}{where}";
                return(sql);
            }
        }