/// <summary>
        ///
        /// </summary>
        /// <param name="ownerKeyBuilder"></param>
        /// <param name="existedKeys"></param>
        /// <param name="mapping"></param>
        /// <returns></returns>
        protected virtual string PrepareUpdateNotMatchedCollectionItemSql(IConnectiveSqlClause ownerKeyBuilder, IConnectiveSqlClause existedKeys, ORMappingItemCollection mapping)
        {
            string innerSql = this.GetJoinedExistedCountSql(ownerKeyBuilder, existedKeys, mapping);

            string endTimeFieldName = GetPropertyFieldName("VersionEndTime", mapping);

            UpdateSqlClauseBuilder updateBuilder = new UpdateSqlClauseBuilder();

            updateBuilder.AppendItem(endTimeFieldName, DBTimePointActionContext.CurrentTimeTSqlVarName, SqlClauseBuilderBase.EqualTo, true);

            WhereSqlClauseBuilder veBuilder = new WhereSqlClauseBuilder();

            veBuilder.AppendItem(endTimeFieldName, DBTimePointActionContext.MaxVersionEndTime);
            veBuilder.AppendItem(GetPropertyFieldName("VersionStartTime", mapping), DBTimePointActionContext.CurrentTimeTSqlVarName, SqlClauseBuilderBase.NotEqualTo, true);

            ConnectiveSqlClauseCollection connective = new ConnectiveSqlClauseCollection(LogicOperatorDefine.And, ownerKeyBuilder, veBuilder);

            string sql = string.Format("UPDATE {0} SET {1} FROM {0} A WHERE {2} AND ({3}) = 0",
                                       this.GetTableName(default(T), mapping),
                                       updateBuilder.ToSqlString(TSqlBuilder.Instance),
                                       connective.ToSqlString(TSqlBuilder.Instance),
                                       innerSql);

            return(sql);
        }
示例#2
0
        protected virtual UpdateSqlClauseBuilder PrepareUpdateSqlBuilder(T obj, ORMappingItemCollection mapping)
        {
            UpdateSqlClauseBuilder updateBuilder = new UpdateSqlClauseBuilder();

            updateBuilder.AppendItem(GetPropertyFieldName("VersionEndTime", mapping), "@currentTime", "=", true);

            return(updateBuilder);
        }
        /// <summary>
        /// 准备更新的Sql Builder。这个方法会在builder中添加VersionEndTime的处理
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="mapping"></param>
        /// <param name="ignoreProperties">需要忽略的属性</param>
        /// <returns></returns>
        public virtual UpdateSqlClauseBuilder PrepareUpdateSqlBuilder(T obj, ORMappingItemCollection mapping, string[] ignoreProperties)
        {
            UpdateSqlClauseBuilder updateBuilder = new UpdateSqlClauseBuilder();

            updateBuilder.AppendItem(GetPropertyFieldName("VersionEndTime", mapping), DBTimePointActionContext.CurrentTimeTSqlVarName, "=", true);

            return(updateBuilder);
        }