NHibernate: Can't Select after Skip Take In Certain Scenario

123 Views Asked by At

For some reason I am unable to use Select() after a Skip()/Take() unless I do this in a certain way. The following code works and allows me to use result as part of a sub query.

var query = QueryOver.Of<MyType>();
query.Skip(1);
var result = query.Select(myType => myType.Id);

However, if I attempt to create the query on one line as below I can't compile.

var query = QueryOver.Of<MyType>().Skip(1);
var result = query.Select(myType => myType.Id);

It looks like the code in the first results in query being of type QueryOver< MyType, MyType> while the second results in query being of type QueryOver< MyType>.

It also works if written like this.

var query = QueryOver.Of<MyType>().Select(myType => myType.Id).Skip(1);

Any ideas why the second version fails horribly when the first and third versions work? It seems like odd behavior.

1

There are 1 best solutions below

0
On

You have a typo in the second version...

var query = QueryOver.Of<MyType().Skip(1);

is missing the >

var query = QueryOver.Of<MyType>().Skip(1);

Not sure if thats what you where looking for.