通用存储库模式和复杂的LINQ查询 [英] Generic Repository Pattern and Complex LINQ Queries

查看:88
本文介绍了通用存储库模式和复杂的LINQ查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用通用存储库方法来实现实体框架代码。如果我需要编写复杂的LINQ查询,那么最好的方法是什么?我认为存储库模式的重点是从存储库访问DBContext而不是直接在我的代码中访问。我应该在哪里创建这个复杂的查询?我不认为我应该使用我的存储库之外的上下文,但我想看看别人对这种情况有什么看法。



谢谢

I am using the generic repository approach to entity framework code first. If I need to write a complex LINQ query, what is the best way to do it? I think the whole point to repository pattern is to access the DBContext from the repository and not directly in my code. Where should I create this complex query? I dont think I should be using the context outside my repository, but I want to see what others have to say about this kind of situation.

Thank you

推荐答案

在通用存储库模式之外编写并不是一个很好的做法,你将破坏拥有存储库模式的整个目的



您可以根据您的特殊要求自定义存储库模式,并且仍然将其存储在存储库模式下,并且不会重新调整以直接访问DBcontext
It is not a good practice to write outside the generic repository pattern and you will be defeating the whole purpose of having the repository pattern

You could customize the repository pattern for your special requirement and still have it under repository pattern and it is not recomanded to access the DBcontext directly


这篇关于通用存储库模式和复杂的LINQ查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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