以下のコードは、mycache.Get( "products")を呼び出すときに"Object reference not set to an instance of an object"
のエラーをスローします。私はWCFアプリケーションを使用しています。私は100%ではないキャッシュを正しく使用しています。何かアドバイス?WCFアプリケーションでのキャッシュ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
namespace DataLayer {
public class Products
{
public List<Product> Current()
{
Cache mycache = new Cache();
if (mycache.Get("products")== null)
{
using (DataLayer.AccessDataContext db = new AccessDataContext())
{
var products = from p in db.fldt_product_to_supp_parts
where p.Current
select new Product
{
WholesaleCode = p.WholesaleCode,
ProductCode = p.Product_Code
};
mycache["products"] = products.ToList();
}
}
return mycache["products"] as List<Product>;
}
} }
EDIT:私はCache
がどのように実装されるか、オフ手知らないので、私は、あなたのコードに問題があるかわからないんだけど、.NET 3.5
私はあなたの質問の残りの部分で "WCF"と読むようにあなたのタイトルを修正しました - 私は正しいことを願っています! –