Beispiel #1
0
        /// <summary>
        /// 从队列中获取n条记录,并进行处理
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public WfPersistQueueCollection FetchQueueItemsAndDoOperation(int count)
        {
            ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(typeof(WfPersistQueue));

            string top = count < 0 ? string.Empty : "TOP " + count;

            string sql = string.Format("SELECT {0} * FROM {1} WITH (UPDLOCK, READPAST) ORDER BY SORT_ID", top, mappingInfo.TableName);

            WfPersistQueueCollection result = new WfPersistQueueCollection();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DataView view = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0].DefaultView;

                ORMapping.DataViewToCollection(result, view);

                foreach (WfPersistQueue pq in result)
                {
                    DoQueueOperationAndMove(pq);
                }

                scope.Complete();
            }

            return(result);
        }
        /// <summary>
        /// 从队列中获取n条记录,并进行处理
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public WfPersistQueueCollection FetchQueueItemsAndDoOperation(int count)
        {
            ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(typeof(WfPersistQueue));

            string top = count < 0 ? string.Empty : "TOP " + count;

            string sql = string.Format("SELECT {0} * FROM {1} WITH (UPDLOCK READPAST) ORDER BY SORT_ID", top, mappingInfo.TableName);

            WfPersistQueueCollection result = new WfPersistQueueCollection();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DataView view = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0].DefaultView;

                ORMapping.DataViewToCollection(result, view);

                foreach (WfPersistQueue pq in result)
                    DoQueueOperationAndMove(pq);

                scope.Complete();
            }

            return result;
        }