0

Using nHibernate QueryOver, if I want to enforce a projection for performance, are "Select" and "Where" the same thing? In other words, will ..

        var member = session.QueryOver<Member>()
            .Select( projections => projections.Email == model.Email )
            .Take(1).SingleOrDefault();

Run the same as

        var member = session.QueryOver<Member>()
            .Where( context => context.Email == model.Email )
            .Take(1).SingleOrDefault();

Or is there a difference in the two?

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
Ciel
  • 17,312
  • 21
  • 104
  • 199

2 Answers2

1

Select projects (you could also say maps); Where filters. This is the same as SQL and all LINQ providers (and QueryOver is also sort of a LINQ provider). It seems that in this case you want to filter, not project, so you need Where

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Thanks. That's what I was going for. I actually got the same result with both queries, but I presumed something else was happening underneath the hood that I might not understand. – Ciel Jun 09 '11 at 13:12
1

No offense intended, but I think the best way to answer a question like the one you asked is to try it. Sometimes things become clearer when you can see the output.

That said, when you use Select, you're telling NHibernate how to project your data. This determines the final makeup of the data resulting from the query. There's a little bit more to this, but that's the general idea. You use Where when you want to specify the criteria that the data that you are querying should satisfy.

csano
  • 13,266
  • 2
  • 28
  • 45
  • 1
    I did try it, and while I received the same data result, that doesn't mean they are the same thing. There are thousands of things going on under the hood in an ORM that a developer of my limited experience doesn't yet grasp. – Ciel Jun 09 '11 at 13:11
  • I wasn't clear. Take a look at the SQL that is generated by the query and you'll see what I'm talking about. I don't know which database system you're using, but if you're using SQL server, you can fire up SQL profiler and see the SQL that is sent to the database. There's also NHibernate Profiler, which is a fantastic tool that shows you precisely what is going on under the covers. – csano Jun 09 '11 at 16:16