IQueryable and ISession

43 Views Asked by At

Which way is better to use?

ISession session = SessionController.Factory.OpenSession();
IQueryable<myObject> myObjectdquery;

1.

myObjectquery = session.Query<myObject>();  
myObjectquery = myObjectquery.Where(x=>x....)

or

2.

myObjectquery = session.Query<myObject>().Where(x=>x...);

I'm not sure is my logic correct but in first approach myObjectquery is first "filled" with data and then queried, and in second approach one step is skipped and myObjectquery is filled only with necessary data. The point is what is faster?

1

There are 1 best solutions below

2
On BEST ANSWER

1.

myObjectquery = session.Query();
myObjectquery = myObjectquery.Where(x=>x....) or

2.

myObjectquery = session.Query().Where(x=>x...);

They are exactly the same thing, just look at it. If you already know that and want to chose which one to go with, go with number 2, it's easier to ready and you have fewer code lines.

P.S: Your query is 'filled' with data in 1st example, but not in memory, so it doesn't matter. So yeah, it's the same thing.