Exemple #1
0
        /// <summary>
        /// 根据具体Model对象生成Update参数及子句
        /// </summary>
        /// <param name="value">更新Model对象,用于生成Update部分,属性为null值的不作为生成条件</param>
        /// <param name="condition">条件Model对象,用于生成Where部分,属性为null值的不作为生成条件</param>
        /// <param name="isLikeMode">是否模糊查询</param>
        /// <returns>Update参数及子句</returns>
        public virtual ParmCollection PrepareUpdateParms(object value, bool isLikeMode = false, object condition = null)
        {
            ParmCollection temp = new ParmCollection();

            string update = string.Empty;

            foreach (IDataParameter p in this.Parameters)
            {
                foreach (DBFieldInfoAttribute f in this.Fields)
                {
                    if (f.ColumnName == p.SourceColumn && f.Field.GetValue(value) != null && f.SqlDbType != SqlDbType.Timestamp)
                    {
                        p.Value = f.Field.GetValue(value);
                        update += string.Format("{0}={1}U, ", f.ColumnNameFix, f.ParameterName);
                        IDataParameter pp = this.CloneParameter(p);
                        pp.ParameterName = f.ParameterName + "U";
                        temp.Add(pp);
                        break;
                    }
                }
            }

            if (update.Length == 0)
            {
                return(temp);
            }

            ParmCollection where = this.PrepareConditionParms(condition, isLikeMode);

            update          = string.Format("UPDATE {0} SET {1}  OUTPUT INSERTED.*  {2}", this.TableName, update.Substring(0, update.Length - 2), "{0}");
            where.UpdateSql = update;

            where.AddRange(temp);
            return(where);
        }
        /// <summary>
        /// ���������ֶ�ֵ���£�model��������κ�ֵ��������Ϊ��������
        /// ��model�г��Զ������ֶ���������в�Ϊnull���ֶν��ᱻ����
        /// </summary>
        /// <param name="model">Ҫ���µ�ֵ</param>
        /// <returns>Ӱ��ļ�¼��</returns>
        public virtual OutputModel UpdateWithIdentityAndReturn(Model model)
        {
            this.setSystemField(model);
            ParmCollection conditionParms = this.Table.PrepareUpdateParms(model);

            conditionParms.AddRange(this.Table.PrepareAllParms(model));
            return(this.Select(string.Format(conditionParms.UpdateSql, this.Table.IdentityParm.WhereSql), conditionParms));
        }
        /// <summary>
        /// ���������ֶ�ֵ���£�model��������κ�ֵ��������Ϊ��������
        /// ��model�г��Զ������ֶ���������в�Ϊnull���ֶν��ᱻ����
        /// </summary>
        /// <param name="models">Ҫ���µ�ֵ����</param>
        /// <returns>Ӱ��ļ�¼��</returns>
        public virtual int UpdateWithIdentity(params Model[] models)
        {
            int returnCount = 0;

            foreach (var model in models)
            {
                this.setSystemField(model);
                ParmCollection conditionParms = this.Table.PrepareUpdateParms(model);
                conditionParms.AddRange(this.Table.PrepareAllParms(model));
                returnCount += this.Internal_DataHelper.ExecuteNonQuery(string.Format(conditionParms.UpdateSql, this.Table.IdentityParm.WhereSql), conditionParms);
            }
            return(returnCount);
        }
        /// <summary>
        /// ���������ֶ�ֵ���£�model��������κ�ֵ��������Ϊ��������
        /// ��model�����г��Զ������ֶ���������в�Ϊnull���ֶν��ᱻ����
        /// </summary>
        /// <param name="models">Ҫ���µ�ֵ����</param>
        /// <returns>���º�Ľ��</returns>
        public virtual IEnumerable <OutputModel> UpdateWithIdentityAndReturn(Model[] models)
        {
            var resultList = new List <OutputModel>();

            foreach (var model in models)
            {
                this.setSystemField(model);
                ParmCollection conditionParms = this.Table.PrepareUpdateParms(model);
                conditionParms.AddRange(this.Table.PrepareAllParms(model));
                var result = this.Select(string.Format(conditionParms.UpdateSql, this.Table.IdentityParm.WhereSql), conditionParms);
                resultList.Add(result);
            }
            return(resultList);
        }