예제 #1
0
 /// <summary>
 /// 获取商品
 /// 商品不存在时返回null,存在时同时获取关联的数据
 /// 结果会按商品Id缓存一定时间
 /// </summary>
 /// <param name="productId"></param>
 /// <returns></returns>
 public virtual Entities.Product GetWithCache(Guid productId)
 {
     return(ProductCache.GetOrCreate(productId, () => {
         using (UnitOfWork.Scope()) {
             var product = Get(productId);
             if (product == null)
             {
                 return null;                         // 商品不存在
             }
             var category = product.Category;
             if (category != null)
             {
                 category.Properties.ToList();
                 category.Properties.SelectMany(p => p.PropertyValues).ToList();
             }
             var seller = product.Seller;
             if (seller != null)
             {
                 var _ = seller.Username;
             }
             product.MatchedDatas.ToList();
             product.PropertyValues.ToList();
             return product;
         }
     }, ProductCacheTime));
 }
예제 #2
0
 /// <summary>
 /// 获取商品
 /// 商品不存在时返回null,存在时同时获取关联的数据
 /// 结果会按商品Id缓存一定时间
 /// </summary>
 /// <param name="productId"></param>
 /// <returns></returns>
 public virtual Database.Product GetProduct(long productId)
 {
     return(ProductCache.GetOrCreate(productId, () =>
                                     UnitOfWork.ReadData <Database.Product, Database.Product>(r => {
         var product = r.GetByIdWhereNotDeleted(productId);
         var category = product.Category;
         if (category != null)
         {
             category.Properties.ToList();
             category.Properties.SelectMany(p => p.PropertyValues).ToList();
         }
         var seller = product.Seller;
         if (seller != null)
         {
             var _ = seller.Username;
         }
         product.MatchedDatas.ToList();
         product.PropertyValues.ToList();
         return product;
     }), ProductCacheTime));
 }