linq - 可以让存储库与服务层返回 View 或 View 模型吗?哪些应该被缓存?

标签 linq azure repository repository-pattern odata

我正在使用 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 的 child 到玩具。

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

由于 AppFabric 缓存,我对 IEnumerable 结果的限制是:

  • 返回的对象不能是值类型
  • 返回的对象必须是可序列化的
  1. How do I implement the IMyRepository to support caching OData queries?
  2. Is it OK for a repository to emit not only model classes, but the "children" aggregate class? What is the proper term for this?
  3. Assuming that the step above is Okay, should I use navigation properties to populate this extra class?

最佳答案

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

关于linq - 可以让存储库与服务层返回 View 或 View 模型吗?哪些应该被缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8131419/

相关文章:

git - DVCS repo 设计 - 使用分支或单独的 repo 将开发与稳定分开?

java - Spring数据存储库: "Containing" for Collections

c# - 忽略联接实体的全局查询过滤器

c# - 将多个类列表合并为 1 个列表

c# - 了解 C# 中的 lambda 表达式

azure - IoT 中心证书验证

azure - 迁移到 Cloudflare 后网站关闭

c# - 如何从 Azure 角色内部检测当前订阅 ID?

c# - Linq OrderBy() 与 List.Sort() 的速度

c# - 在域和存储库之间共享实用程序对象