Esempio n. 1
0
        private StringBuilder Build()
        {
            var sql = new StringBuilder();

            var type = typeof(T);

            var(tableName, properties) = ProviderHelper.GetMetas(type);

            var selectSql = new StringBuilder();

            if (_selectField.Length > 0)
            {
                selectSql.Append(_selectField);
            }
            else
            {
                foreach (var property in properties)
                {
                    selectSql.Append($"{property.ColumnName} as {property.Parameter},");
                }

                selectSql.Remove(selectSql.Length - 1, 1);
            }


            sql.Append($"select {selectSql} from {tableName} {prefix} ");

            sql.Append(whereCommand.Build().Replace(DatabaseFactory.ParamterSplit, DbPrefix));

            return(sql);
        }
Esempio n. 2
0
        private StringBuilder Build()
        {
            var sql = new StringBuilder();

            var type = typeof(T);

            var(tableName, properties) = ProviderHelper.GetMetas(type);

            sql.Append($"update {tableName} set ");

            if (_selectProvider.SelectFields.Any())
            {
                _selectProvider.SelectFields.ForEach(t =>
                {
                    sql.Append($" {t.ColumnName} = {DbPrefix}{t.Parameter},");
                });

                sql.Remove(sql.Length - 1, 1);
                sql.Append(" where ");

                foreach (var member in properties.Where(t => t.IsPrimaryKey))
                {
                    sql.Append($" {member.ColumnName} = {DbPrefix}{member.Parameter} and");
                }
            }
            else
            {
                var existProperty = properties.Where(p => !p.IsPrimaryKey && _ignoreProvider.SelectFields.All(t => t.ColumnName != p.ColumnName));
                foreach (var p in existProperty)
                {
                    sql.Append($" {p.ColumnName} = {DbPrefix}{p.Parameter},");
                }

                sql.Remove(sql.Length - 1, 1);
                sql.Append(" where ");

                foreach (var member in properties.Where(t => t.IsPrimaryKey))
                {
                    sql.Append($" {member.ColumnName} = {DbPrefix}{member.Parameter} and");
                }
            }

            sql.Remove(sql.Length - 3, 3);

            return(sql);
        }
Esempio n. 3
0
        private StringBuilder Build()
        {
            var sql = new StringBuilder();

            var type = typeof(T);

            var(tableName, _) = ProviderHelper.GetMetas(type);

            sql.Append($"update {tableName} set ");


            sql.Append(setSql);

            sql.Remove(sql.Length - 1, 1);

            sql.Append(whereCommand.Build().Replace(DatabaseFactory.ParamterSplit, DbPrefix));


            return(sql);
        }