问题描述
我有一个MVC应用程序,该应用程序直接在视图中使用该实体框架模型对象.我不确定这对设计模式有多严重,但是基于此示例我需要使用存储库来实现缓存.
I have a MVC application that uses that entity framework model object directly in the view. I'm not sure how bad of a design pattern this is, but based on this sample I need to use a repository to implement caching.
namespace MVCAzureStore.Services.Caching
{
public class CachedProductsRepository : CachedDataSource, IProductRepository
{
private readonly IProductRepository repository;
public CachedProductsRepository(IProductRepository repository, ObjectCache cacheProvider) :
base(cacheProvider, "Products")
{
this.repository = repository;
}
public List<string> GetProducts()
{
return RetrieveCachedData(
"allproducts", () => this.repository.GetProducts(),
new CacheItemPolicy { AbsoluteExpiration = DateTime.UtcNow.AddMinutes(1) });
}
}
}
由于此视图使用了EF的导航属性,因此我需要复制此概念(或在我的视图中有类似的东西).
Since this view uses the navigation properties of the EF I need to replicate this notion(or have something similar in mine).
问题
任何代码示例,文章或更多信息都将受到赞赏,因为我以这种方式学习得最好
Any code sample, article, or more info would be appreciated, since I learn best that way
推荐答案
请参阅本教程中的存储库,该存储库使您可以为指定的导航属性指定紧急加载: http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
See the repository in this tutorial, which allows you to specify eager loading for specified navigation properties:http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
这篇关于当使用多个1:Many或Many:Many表时,存储库是什么样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!