コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sqlContext"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        protected virtual string InnerDeleteInContext(T data, SqlContextItem sqlContext, Dictionary <string, object> context)
        {
            ORMappingItemCollection mappings = GetMappingInfo(context);

            string sql = this.GetDeleteSql(data, mappings, context);

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);

            return(sql);
        }
コード例 #2
0
        /// <summary>
        /// 在上下文中生成删除数据的SQL(时间封口)
        /// </summary>
        /// <param name="data"></param>
        /// <param name="ignoreProperties"></param>
        public void DeleteInContext(T data, params string[] ignoreProperties)
        {
            data.NullCheck("data");

            Dictionary <string, object> context = new Dictionary <string, object>();

            SqlContextItem sqlContext = this.GetSqlContext();

            this.BeforeInnerDeleteInContext(data, sqlContext, context);

            string sql = VersionStrategyUpdateSqlBuilder <T> .DefaultInstance.ToDeleteSql(data, this.GetMappingInfo(), false, ignoreProperties);

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ownerKeyBuilder"></param>
        /// <param name="data"></param>
        /// <param name="ignoreProperties">需要忽略的属性</param>
        public void UpdateCollectionInContext(IConnectiveSqlClause ownerKeyBuilder, IEnumerable <T> data, params string[] ignoreProperties)
        {
            ownerKeyBuilder.NullCheck("ownerKeyBuilder");
            data.NullCheck("objs");

            Dictionary <string, object> context = new Dictionary <string, object>();

            SqlContextItem sqlContext = this.GetSqlContext();

            this.BeforeInnerUpdateCollectionInContext(data, sqlContext, context);

            string sql = VersionStrategyUpdateSqlBuilder <T> .DefaultInstance.ToUpdateCollectionSql(ownerKeyBuilder, this.GetMappingInfo(), data, false, ignoreProperties);

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);
        }
コード例 #4
0
        /// <summary>
        /// 在上下文中注册查询返回的结果
        /// </summary>
        /// <param name="sqlContext">Sql语句上下文</param>
        /// <param name="tableName"></param>
        /// <param name="mapping"></param>
        /// <param name="sql"></param>
        /// <param name="action"></param>
        /// <param name="createNewAction"></param>
        public void RegisterQueryData(SqlContextItem sqlContext, string tableName, ORMappingItemCollection mapping, string sql, Action <TCollection> action, Func <DataRow, T> createNewAction)
        {
            sqlContext.NullCheck("sqlContext");

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);
            sqlContext.RegisterTableAction(tableName, (table) =>
            {
                TCollection collection = this.DataTableToCollection(mapping, table, createNewAction);

                if (action != null)
                {
                    action(collection);
                }
            });
        }
コード例 #5
0
        /// <summary>
        /// 执行UpdateInContext的时序,操作由应用定义
        /// </summary>
        /// <param name="data"></param>
        /// <param name="updateAction"></param>
        /// <param name="insertAction"></param>
        /// <param name="afterAction"></param>
        protected void DoUpdateInContext(T data,
                                         Action <T, SqlContextItem, Dictionary <string, object> > updateAction,
                                         Action <T, SqlContextItem, Dictionary <string, object> > insertAction,
                                         Action <T, SqlContextItem, Dictionary <string, object> > afterAction = null)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(data != null, "data");

            Dictionary <string, object> context = new Dictionary <string, object>();

            SqlContextItem sqlContext = this.GetSqlContext();

            updateAction.IsNotNull(action => action(data, sqlContext, context));

            sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, "IF @@ROWCOUNT = 0");

            sqlContext.AppendSqlInContext(TSqlBuilder.Instance, "\nBEGIN\n");
            insertAction.IsNotNull(action => action(data, sqlContext, context));
            sqlContext.AppendSqlInContext(TSqlBuilder.Instance, "\nEND\n");

            afterAction.IsNotNull(action => action(data, sqlContext, context));
        }
コード例 #6
0
        /// <summary>
        /// 在上下文中添加删除对象的脚本
        /// </summary>
        /// <param name="whereAction"></param>
        public virtual void DeleteInContext(Action <WhereSqlClauseBuilder> whereAction)
        {
            whereAction.NullCheck("whereAction");

            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            whereAction(builder);

            Dictionary <string, object> context = new Dictionary <string, object>();

            SqlContextItem sqlContext = this.GetSqlContext();

            this.BeforeInnerDeleteInContext(builder, sqlContext, context);

            string sql = this.GetDeleteSql(builder, context);

            if (sql.IsNotEmpty())
            {
                sqlContext.AppendSqlWithSperatorInContext(TSqlBuilder.Instance, sql);

                this.AfterInnerDeleteInContext(builder, context);
            }
        }