Linq OrderBy an expression

128 views
Skip to first unread message

Andrew Davey

unread,
Dec 4, 2010, 12:19:19 PM12/4/10
to ravendb
Is it possible to have something like:

var query = session.Query<Thing>().Where(...);
var defaultDate = DateTime.UtcNow.AddDays(1);
query.OrderBy(x => x.Date.HasValue ? x.Date : defaultDate);

?

When executing, I get an exception:
Unable to cast object of type
'System.Linq.Expressions.FullConditionalExpression' to type
'System.Linq.Expressions.MemberExpression'

Is this a limitation of the linq api or the underlying system?

Can someone suggest an alternative approach please?

Rob Ashton

unread,
Dec 4, 2010, 1:28:21 PM12/4/10
to ravendb
That would be quite challenging I think, unless we had *specific*
handling for this particular scenario (a hack)

Ayende Rahien

unread,
Dec 4, 2010, 1:44:13 PM12/4/10
to ravendb
No, we can't handle that scenario.

Ayende Rahien

unread,
Dec 4, 2010, 1:45:05 PM12/4/10
to ravendb
RavenDB doesn't allow any sort of computation in the indexing stage.
What you can do is emit the Date field in the index with whatever logic you have in it, which will allow you to get the same result.

Andrew Davey

unread,
Dec 4, 2010, 6:28:23 PM12/4/10
to ravendb
How about adding support for null coalescing? e.g. detect calls to
Nullable<T>.GetValueOrDefault(someVar)
That would work for my use case.

Andrew Davey

unread,
Dec 4, 2010, 6:35:06 PM12/4/10
to ravendb
I'm not very familiar with creating more complex indexes (I've been so
happy with the dynamic index magic!)
Could you give a brief example of what I need to do? Should I use an
AbstractIndexCreationTask<T> to do it?
Reply all
Reply to author
Forward
0 new messages