Modifying indexing behavior

64 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Jan 12, 2012, 1:11:28 AM1/12/12
to ravendb
One of the more annoying behaviors for C# with dynamic binding is that it requires to handle labmda casting.
In other words, this will fail to compile:

foo.Where(x=>x.Name == "foo")

You have to write it as:

foo. Where ((Func<dynamic,bool>)(x=>x.Name == "foo"))

As things gets complex, this gets really annoying.

I just finished doing a major modification to RavenDB that should drastically simplify this behavior. 
That said, this is a pretty big change, we have got 1,300+ tests that says that everything is okay, but I wanted to let you know that this is a major (internal) change.

I would ask you to test the latest unstable build and to see if that works well in your scenarios.

nightwatch

unread,
Jan 12, 2012, 2:37:58 AM1/12/12
to ravendb
Interesting. I did something like this recently (in a completely
different project) and casting wasn't required.
I have a function, say
ISomething Where(Func<dynamic, QueryExpr> f)
and I can write
Where(x => x.Name == "foo")
without any casting.
But maybe my context is totally different

On 12 Sty, 07:11, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Matt Warren

unread,
Jan 12, 2012, 4:29:16 AM1/12/12
to rav...@googlegroups.com
Will this also remove the need to do casting when using Sum/Avg etc in Map/Reduce indexes?

Oren Eini (Ayende Rahien)

unread,
Jan 12, 2012, 10:08:03 AM1/12/12
to rav...@googlegroups.com
Yes, that is the idea.

Oren Eini (Ayende Rahien)

unread,
Jan 12, 2012, 10:33:08 AM1/12/12
to rav...@googlegroups.com
You need to go one level down:

var docs = new dynamic[0];

var q = from doc in docs
            select new { Users = doc.Users.Select(x=>x.Name) }

That won't work without casting.
Reply all
Reply to author
Forward
0 new messages