Beispiel #1
0
        public DbCommand Get(Type type, Database db, Command cmdWrapper)
        {
            var       map = MapConverter.GetPropertyData(type);
            DbCommand cmd = null;

            if (cmdWrapper.Procedures.IsNotNullOrEmpty())
            {
                var table = cmdWrapper.Procedures.FirstOrDefault(p => p.Table == map.Table);
                if (table != null)
                {
                    map.InsertSP = table.InsertSP;
                    map.UpdateSP = table.UpdateSP;
                    map.DeleteSP = table.DeleteSP;
                }
            }

            if (map.DeleteSP.IsNotNullOrEmpty())
            {
                cmd = db.GetStoredProcCommand(map.DeleteSP);
            }
            else
            {
                cmd = db.GetSqlStringCommand(string.Format(SQL_DELETE, map.Table, PK_ID));
                //数据版本管理
                if (map.IsRowVersion)
                {
                    cmd.CommandText += string.Format(" AND {0}=@{0} ", Constant.FieldName_RowVersion);
                    db.AddInParameter(cmd, Tool.Str_Alpha + Constant.FieldName_RowVersion, DbType.Int32, Constant.FieldName_RowVersion, DataRowVersion.Current);
                }
            }
            db.AddInParameter(cmd, Tool.Str_Alpha + PK_ID, DbType.String, PK_ID, DataRowVersion.Current);

            return(cmd);
        }
Beispiel #2
0
        public DbCommand Get(Type type, Database db, Command cmdWrapper)
        {
            DbCommand cmd = null;
            var       map = MapConverter.GetPropertyData(type);
            var       key = map.Fields.FirstOrDefault(p => p.IsKey);

            if (key != null)
            {
                var sb = new StringBuilder();
                foreach (var field in map.Fields)
                {
                    if (field.IsUpdate)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(Tool.Str_Comma);
                        }
                        sb.Append(field.Field);
                    }
                }
                if (sb.Length > 0)
                {
                    cmd = db.GetSqlStringCommand(string.Format(SQL_SELECT, map.Table));
                }
            }
            return(cmd);
        }
Beispiel #3
0
        public DbCommand Get(Type type, Database db, Command cmdWrapper)
        {
            var map = MapConverter.GetPropertyData(type);
            List <FieldInfo> fieldList = GetFieldList(type, cmdWrapper, map);
            DbCommand        cmd       = null;

            if (cmdWrapper.Procedures.IsNotNullOrEmpty())
            {
                var table = cmdWrapper.Procedures.FirstOrDefault(p => p.Table == map.Table);
                if (table != null)
                {
                    map.InsertSP = table.InsertSP;
                    map.UpdateSP = table.UpdateSP;
                    map.DeleteSP = table.DeleteSP;
                }
            }

            if (map.UpdateSP.IsNotNullOrEmpty())
            {
                cmd = db.GetStoredProcCommand(map.UpdateSP);
                SetUpdateFieldsForSP(fieldList, db, cmd);
            }
            else
            {
                cmd             = db.GetSqlStringCommand(SQL_NULL);
                cmd.CommandText = null;

                if (fieldList.IsNotNullOrEmpty())
                {
                    var updateSql = new StringBuilder();
                    updateSql.Append(string.Format(SQL_UPDATE_PART1, map.Table));

                    SetUpdateFields(fieldList, updateSql, db, cmd);
                    string whereText = string.Format(SQL_UPDATE_PART2, PK_ID);
                    //数据版本管理
                    if (map.IsRowVersion)
                    {
                        whereText += string.Format(" AND {0}=@{0} ", Constant.FieldName_RowVersion);
                        db.AddInParameter(cmd, Tool.Str_Alpha + Constant.FieldName_RowVersion, DbType.Int32, Constant.FieldName_RowVersion, DataRowVersion.Current);
                    }
                    cmd.CommandText = updateSql.ToString() + whereText;
                    AddPkParameter(fieldList, db, cmd);
                }
            }

            return(cmd);
        }
Beispiel #4
0
        public DbCommand Get(Type type, Database db, Command cmdWrapper)
        {
            var map        = MapConverter.GetPropertyData(type);
            var properties = map.Fields.Where(p => p.Field.IsNotNullOrEmpty() && p.IsUpdate).ToList();

            if (properties != null && properties.Count > 0)
            {
                DbCommand cmd = null;

                if (cmdWrapper.Procedures.IsNotNullOrEmpty())
                {
                    var table = cmdWrapper.Procedures.FirstOrDefault(p => p.Table == map.Table);
                    if (table != null)
                    {
                        map.InsertSP = table.InsertSP;
                        map.UpdateSP = table.UpdateSP;
                        map.DeleteSP = table.DeleteSP;
                    }
                }

                if (map.InsertSP.IsNotNullOrEmpty())
                {
                    cmd = db.GetStoredProcCommand(map.InsertSP);
                    SetUpdateFieldsForSP(properties, db, cmd);
                }
                else
                {
                    cmd             = db.GetSqlStringCommand(SQL_NULL);
                    cmd.CommandText = null;

                    var fields = new StringBuilder();
                    fields.Append(string.Format(SQL_INSERT_PART1, map.Table));

                    var values = new StringBuilder();
                    values.Append(SQL_INSERT_PART2);

                    SetUpdateFields(properties, db, cmd, fields, values);
                    fields.Append(RIGHT_BRACKET);
                    values.Append(RIGHT_BRACKET);
                    cmd.CommandText = fields.ToString() + values.ToString();
                }
                return(cmd);
            }
            return(null);
        }