-2

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?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Josef
  • 2,648
  • 5
  • 37
  • 73
  • 3
    There is no difference. In both cases you call `Query` on `session` and `Where` on the result of that call. – René Vogt Mar 18 '19 at 13:31

1 Answers1

1

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.

Cata Hotea
  • 1,811
  • 1
  • 9
  • 19
  • "Your query is 'filled' with data in 1st example, but not in memory" What does this mean? The variable just references a _query_, no data, in memory or otherwise. – D Stanley Mar 18 '19 at 14:19
  • Yes, i agree with you. Here is what he wrote: "I'm not sure is my logic correct but in first approach myObjectquery is first "filled" with data and then queried". I was simply telling him that it makes no difference, cause no data is actually loaded at all. – Cata Hotea Mar 18 '19 at 14:22