【问题标题】:OK to have Views or ViewModels returned by the Repository vs Service Layer? Which should be cached?可以让存储库与服务层返回视图或视图模型吗?应该缓存哪个?
【发布时间】:2011-12-29 04:57:25
【问题描述】:

我正在使用 Azure AppFabric 通过全新的存储库进行缓存。我的存储库看起来像这样:

public interface IMyRepository
{
  public IEnumerable<K> Select(IQueryable<T> someQuery) 
  public IEnumerable<T> SelectAllStudents()  // should I replace T with Children in my repository?
}

我的意图是公开和缓存来自客户端的 OData 请求,因此是 IQueryable。我还有一个次要需求是经常返回看起来像这样的数据

public class Children
{
  public string Name {get;set;}

  public int CountOfToys {get;set;}

  public List<Toys> {get;set;}
}

但是我的数据库是儿童玩具的1..many

当前的 ASP.NET 应用程序直接在 aspx 页面中使用 EF 的导航属性来填充上面的 ViewModel,但是我不知道最有效的路由端口这个功能到存储库。

由于 AppFabric 缓存了我对 IEnumerable 结果的约束:

  • 返回的对象不能是值类型
  • 返回的对象必须是可序列化的
  1. 如何实现 IMyRepository 以支持缓存 OData 查询?
  2. 存储库不仅可以生成模型类,还可以生成“子”聚合类吗?什么是合适的术语?
  3. 假设上面的步骤没问题,我应该使用导航属性来填充这个额外的类吗?

【问题讨论】:

  • This answer 让我觉得我应该离开存储库 IQueryable,然后缓存服务层。想法?

标签: linq azure repository repository-pattern odata


【解决方案1】:

缓存存储库实体将更容易控制,这意味着您的系统中有一个内存数据库,但性能和灵活性较低。缓存域对象可以提高性能,因为它更接近您实际想要缓存的内容。但是您需要考虑缓存项之间的同步。我想通过引入一个单独的缓存管理器组件来缓存服务层。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-09
    • 2010-11-24
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多