开发者

nHibernate QueryOver Projects - are Select and Where the same thing?

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>()
       开发者_StackOverflow中文版     .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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜