在prefetching数据LINQ到SQL,国际奥委会和存储库模式 [英] Prefetching data in with Linq-to-SQL, IOC and Repository pattern

查看:136
本文介绍了在prefetching数据LINQ到SQL,国际奥委会和存储库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LINQ到SQL我想prefetch一些数据。

using Linq-to-SQL I'd like to prefetch some data.

1)常见的解决方案是应对 DataLoadOptions ,但在我的建筑将无法工作,因为:

1) the common solution is to deal with DataLoadOptions, but in my architecture it won't work because :


  • 选项都在第一查询之前设置

  • 我使用的是国际奥委会,所以不直接实例化DataContext的(我不能执行在instanciation code)

  • 我的DataContext是一个Web请求期间
  • 持续

2)我见过的基础上的调用数据和它的子中的方法,那么只返回数据(所以孩子已经装入)另一种可能性< A HREF =htt​​p://www.west-wind.com/weblog/posts/38838.aspx相对=nofollow>在这里看到一个例子

2) I have seen another possibility based on loading the data and its childs in a method, then returning only the data (so the child is already loaded) see an example here

然而,在我的架构,它不能不起作用:

Nonetheless, in my architecture, it cannot not work :


  • 我的查询级联了我的资料库,并且可以通过许多服务消费将增加的条款

  • 我和接口工作,LINQ到SQL对象不离开仓库的具体情况(是的,你可以用接口工作,并增加条款)

  • 我的仓库是通用

是的,这种架构是安静复杂,但它非常酷,因为我可以用code像乐高玩;)

Yes, this architecture is quiet complicated, but it's very cool as I can play with the code like lego ;)

我的问题是:什么是其他可能性以prefetch数据

My question is : what are the other possibilities to prefetch a data ?

推荐答案

在我的应用我使用也许变化给你的潜在解决方案#2。这有点难以解释,但简单地说:我链和推迟延迟加载在我的模型使用自定义的lazy班的,以抽象的从LinqToSql具体执行递延我有机可乘与的IQueryable 之遥。优点:

In my app i use perhaps a variation to your potential solution #2. It's somewhat difficult to explain but simply: i chain and defer lazy loading in my model with custom lazy classes so as to abstract away from the LinqToSql-specific Differed Execution that i take advantage of with IQueryable. Benefits:


  • 我的域模型和服务层向上不必依赖于LinqToSql提供商(我可以用接口换出我DAL,如果我愿意的话)

  • 我的服务方法都可以做,它为使用类,抽象延迟加载离开特定的延迟加载实现多个锚点返回完整的对象图 - 这样我就可以使用特定LinqToSql - 递延执行或别的东西(如匿名委托。再次,请参阅<一个href=\"http://stackoverflow.com/questions/1669607/is-this-repository-pattern-efficient-with-linq-to-sql/1695561#answer-1695561\">this答案)

  • 我能保持的IQueryable 结果在我的应用程序(甚至到了UI,如果我想),从而允许无限的LINQ查询链接,而无需担心性能。

  • My Domain Model and Service layer upwards does not necessarily have to depend on the LinqToSql provider (i can swap out my DAL with interfaces if i want to)
  • My Service methods can and do return complete object graphs with multiple 'anchor points' for lazy loading using classes that abstract away a particular lazy loading implementation - so i can use LinqToSql-specific Differed Execution or something else (eg. anon delegates. again, refer to this answer)
  • I can maintain IQueryable results throughout my app (even to the UI if i want to) thus allowing infinite LINQ query chaining without having to worry about performance.

这篇关于在prefetching数据LINQ到SQL,国际奥委会和存储库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆