Esempio n. 1
0
        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public ProductDto GetProductInfo(int productId)
        {
            Console.WriteLine("---------2,--Session ID:{0}----------", base.CurrentContext.Session.SessionID);

            /*
             * 采用NOLOCK 方式查询
             * ProductDbContext context = new ProductDbContext();
             * ProductEntity entity= OQL.From<ProductEntity>().With(OQL.SqlServerLock.NOLOCK )
             *  .Select()
             *  .Where((cmp, p) => cmp.Comparer(p.ID,"=",productId))
             *  .END
             *  .ToObject(context.CurrentDataBase);
             */
            //下面采用更新库存的事务连接对象,不需要NoLock
            ProductDbContext context = base.CurrentContext.Session.Get <ProductDbContext>("DbContext");
            ProductEntity    entity  = OQL.From <ProductEntity>()
                                       .Select()
                                       .Where((cmp, p) => cmp.Comparer(p.ID, "=", productId))
                                       .END
                                       .ToObject(context.CurrentDataBase);

            ProductDto dto = new ProductDto();

            if (entity != null)
            {
                //entity.MapToPOCO(dto);
                entity.CopyTo <ProductDto>(dto);
            }
            return(dto);
        }
        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public ProductDto GetProductInfo(int productId)
        {
            ProductDbContext context = new ProductDbContext();
            ProductEntity    entity  = OQL.From <ProductEntity>().With(OQL.SqlServerLock.NOLOCK)
                                       .Select()
                                       .Where((cmp, p) => cmp.Comparer(p.ID, "=", productId))
                                       .END
                                       .ToObject(context.CurrentDataBase);
            ProductDto dto = new ProductDto();

            if (entity != null)
            {
                //entity.MapToPOCO(dto);
                entity.CopyTo <ProductDto>(dto);
            }
            return(dto);
        }