コード例 #1
0
        public string Build(bool ignorePrefix = true)
        {
            var sql = new StringBuilder();

            var type = typeof(T);

            var(tableName, properties) = DaoHelper.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, paramterPrefix));

            return(sql.ToString());
        }
コード例 #2
0
        public string Build(bool ignorePrefix = true)
        {
            var columnList    = new List <string>();
            var parameterList = new List <string>();

            var type = typeof(T);

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

            foreach (var p in properties)
            {
                if (p.IsIdentity)
                {
                    continue;
                }

                columnList.Add(p.ColumnName);
                parameterList.Add($"{paramterPrefix}{p.Parameter}");

                //Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(_model));
            }

            StringBuilder sql = new StringBuilder();

            sql.Append($"insert into {tableName} ({string.Join(",", columnList)}) values ({string.Join(",", parameterList)})");

            return(sql.ToString());
        }
コード例 #3
0
ファイル: Saveable.cs プロジェクト: geniuscynic/framework
        public string Build(bool ignorePrefix = true)
        {
            var sql = new StringBuilder();

            var type = typeof(T);

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

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

            if (_visitor.UpdatedFields.Any())
            {
                _visitor.UpdatedFields.ForEach(t =>
                {
                    sql.Append($" {t.ColumnName} = {paramterPrefix}{t.Parameter},");
                });

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

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

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

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

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

            return(sql.ToString());
        }
コード例 #4
0
        public string Build()
        {
            var sql = new StringBuilder();

            var type = typeof(T);

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

            sql.Append($"delete from {tableName}  ");

            //sql.Append(" where ");

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

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


            return(sql.ToString());
        }
コード例 #5
0
        public string Build(bool ignorePrefix = true)
        {
            var sql = new StringBuilder();

            var type = typeof(T);

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

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


            sql.Append(setSql);

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

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


            return(sql.ToString());
        }