コード例 #1
0
        /// <summary>
        /// 在DB上下文中插入一条新日志,用于之入库
        /// </summary>
        /// <param name="data"></param>
        public void InsertDataInContext(UserOperationLog data)
        {
            data.NullCheck("data");

            SqlContextItem sqlContext = this.GetSqlContext();

            this.InnerInsertInContext(data, sqlContext, this.GetFixedContext(), StringExtension.EmptyStringArray);
            sqlContext.AppendSqlInContext(TSqlBuilder.Instance, TSqlBuilder.Instance.DBStatementSeperator);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sqlContext"></param>
        /// <param name="context"></param>
        /// <param name="ignoreProperties">需要忽略的属性</param>
        /// <returns></returns>
        protected virtual string InnerInsertInContext(T data, SqlContextItem sqlContext, Dictionary <string, object> context, string [] ignoreProperties)
        {
            ORMappingItemCollection mappings = GetMappingInfo(context);

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

            sqlContext.AppendSqlInContext(TSqlBuilder.Instance, sql);

            return(sql);
        }
コード例 #3
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));
        }