0

Assuming: This solution will for the forseeable future allways be MS, C#, .Net, SQL Server, Entity Framework and the the DAL, BLL etc will not be passed around to outside sources, but may be used in separate applications of the same suite

A. Should I use Linq and IQueryable to implement the Query object Pattern and forget about dealing with Repositories and/or DAO's ?

B. What must I do/implemet if anything to fit the pattern? Haven't found much example how to's on this.

Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
JAMES
  • 27
  • 4
  • I am using the technique outlined [in this answer](http://stackoverflow.com/a/9943907/572644) very successfully. – Daniel Hilgarth Jan 23 '13 at 22:59
  • Sorry Daniel, I just saw you=r link now. Thansk. Shouild get me started -- thanks – JAMES Jan 24 '13 at 17:45
  • Daniel, So you are using Linq fopr your queries right? Becasue in one comment you say that is bad do to different Query results with different providers. Just curious, i would be using different providers though – JAMES Jan 24 '13 at 18:03
  • That's exactly the point of the linked answer: You provide an interface to your business code that doesn't use `IQueryable` (LINQ to X). So, the business layer is free of the problems that `IQueryable` has. How you implement the queries in the DAL is secondary. You can implement them using LINQ, you can implement them using NHibernates criteria API, you can even implement them using plain old SQL. – Daniel Hilgarth Jan 24 '13 at 18:25

1 Answers1

0

I think you miss something across technologies vs patterns. Linq is some kind of low level technologies to working with data in pretty useful manner. But it's not a pattern and have no any connections to it.

From the other hand if you want to implement query object pattern (which is quite a good idea, if you need to implement quite straightforward data querying features, and you could query your data with the multiples way), you could implement it using Linq or without. It's completely up to you. And linq itself couldn't help you to implement query object.

Also, even if you decide to implement data accessing layer with help of query object, that's doesn't mean that you no need to use Service or Repository pattern. In most of the cases, especially if you are using reach query features you should be able to implement both, because it's very hard to implement service or repository which have all the methods you need.

But anyway, for the complex project allow users use IQueryable outside your DAL code will cause to serious problem. Short example: some of your data changes and now it contains ID1 fields insted ID field. If you have the single way to query your data you just change the code in one place, but if you allow just to use IQueryable everywhere, then you need to find all the places where ID used and replace it to ID1.

And also, if you have quite a poor query features, then you most of all no need neither query object nor repositories etc. Active record pattern will be pretty sure enough.

Ph0en1x
  • 9,943
  • 8
  • 48
  • 97
  • I got the idea about link from several different posting/blogs I had found while searching for informatuion on thes patterns. I read this here http://stackoverflow.com/questions/11964578/repository-iqueryable-query-object/11980291#11980291 and a few other otherss I cant remember off the top of my head, but that was what my question was. What i would like to know thous=ge is if there is a good source/example for getting started with the Query Object pattern using IQueryable and Ling -Thanks – JAMES Jan 24 '13 at 16:46
  • I think that the author of the best answer is pretty much wrong in his opinion. his approach is normal for small project with pure querying part (in my answer I also told you that it will be over engineering, but using his approach in big project will cause code duplicate, copypasting, mistakes and a lot of others problem) – Ph0en1x Jan 24 '13 at 16:54
  • I just saw this article too that says Linq is QO Pattern http://besnikgeek.blogspot.com/2010/08/specification-pattern-versus-query Still thinking on it... thanks – JAMES Jan 24 '13 at 16:58
  • Yeah, it is. For some level of abstractions linq is query object implementation. But it's connected only to low level linq implementation and not connected your DAL at all. It will be wrong to say: Guys, I'm using QO pattern in DAL of my app, because I using linq. – Ph0en1x Jan 24 '13 at 17:02
  • Not sure I follow you. I wil be usign Entity Framework, and queying the business object throguh tjat, I will not be going direct to the DAL found a 3rd one here too \\http://stackoverflow.com/questions/7077729/query-object-pattern-vs-linq Still thinking on it... thanks – JAMES Jan 24 '13 at 17:08
  • DAL - is data access layer. It's every code that you use to query your data. – Ph0en1x Jan 24 '13 at 17:10
  • I see what you asking. At least =) You asking about passing linq expression like a parameter to query data. In that case I agree with the Daniel's answer. – Ph0en1x Jan 24 '13 at 17:14
  • Ok ,so the other part to my question is what do i need to create in code and what parts of Linq allready do the Query Objects. Where to start? so that I am doing it right -- thanks – JAMES Jan 24 '13 at 17:29
  • Oh, WRT Daniels comment, he is talking abiout different DALS. I wont have different DALs. First part of my question. We will be pure MS, EF, SQL Server for the forseale future thanks – JAMES Jan 24 '13 at 17:40