'System.Array' does not contain a definition for 'Take'

1,622 views
Skip to first unread message

katoa

unread,
Jan 21, 2016, 12:24:45 PM1/21/16
to RavenDB - 2nd generation document database
 Here is a very simplified version of a transform I'm trying to create:

TransformResults = users =>
    from user in users
    let subpartcount = { calculation }
    select new
    {
        user.Id,
        SubParts = user.Parts.Split(' ').Take(subpartcount)
        //SubParts = Enumerable.Take(user.Parts.Split(' '), subpartcount)
        //SubParts = Enumerable.Take((IEnumerable<string>)user.Parts.Split(' '), subpartcount)
    };


My first attempt is the code not commented out.   After searching through the forum, I see that the server can't deal with LINQ extension methods, so I tried the other commented out attempts, but with the same exception.

Perhaps this is because Take itself is implemented using an internal extension method?

In any case, how can I do this?

Chris Marisic

unread,
Jan 21, 2016, 12:51:08 PM1/21/16
to RavenDB - 2nd generation document database
You're not enumerating the Take() result leaving it as a deferred enumerable. This is probably causing problems. 

katoa

unread,
Jan 22, 2016, 1:48:03 AM1/22/16
to RavenDB - 2nd generation document database
True, but adding a ToArray() after the Take to force enumeration (whether extension method or direct call) still results in the same exception.

Oren Eini (Ayende Rahien)

unread,
Jan 22, 2016, 2:53:06 AM1/22/16
to ravendb
The actual issue is that the Split() method returns an System.Array, while for most things in RavenDB we rely on an internal class that knows how to map common extension methods.
Your usage of the Enumerable.Take() method is good, but the problem is that you are doing that as a C# code, and as far as the compiler is concerned, both options are identical.

This might work:

        SubParts = ((string[])user.Parts.Split(' ')).Take(subpartcount)



Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Marisic

unread,
Jan 22, 2016, 10:24:29 AM1/22/16
to RavenDB - 2nd generation document database
Are you sure about that?

From resharper decompile:

    [ComVisible(false)]
    [__DynamicallyInvokable]
    public string[] Split(string[] separator, StringSplitOptions options)




public string[] Split(

Oren Eini (Ayende Rahien)

unread,
Jan 22, 2016, 11:02:27 AM1/22/16
to ravendb
Yes, I am.
It isn't anything to do with _invoking_ Split(), it is about being able to bind an extension method to it in dynamic context.
That isn't allowed, which is something that you generally don't notice in ravendb because we work very hard to make sure that this is the case

Chris Marisic

unread,
Jan 22, 2016, 12:29:05 PM1/22/16
to RavenDB - 2nd generation document database
got it, dynamic context makes it odd.

katoa

unread,
Jan 22, 2016, 12:58:00 PM1/22/16
to RavenDB - 2nd generation document database
Yep, that did the trick.   And I understand the difficulties involved.

Thanks!
Reply all
Reply to author
Forward
0 new messages