Query Index "Unable to cast object of type ... to type ..."

209 views
Skip to first unread message

Scott

unread,
Mar 22, 2013, 7:00:35 PM3/22/13
to rav...@googlegroups.com
I think I have the most simple index possible:

public class ZipCodesWithAgent : AbstractIndexCreationTask<ZipCode, ZipCodesWithAgent.Result>
{
        public class Result
        {
            public ZipCode ZipCode { get; set; }
            public Agent Agent { get; set; }            
        }

        public ZipCodesWithAgent()
        {
            Map = zipcodes => from zip in zipcodes
                              select new
                              {
                                  ZipCode = zip,
                                  Agent = LoadDocument<Agent>(zip.AgentId)
                              };

            Store(x => x.Agent, Raven.Abstractions.Indexing.FieldStorage.Yes);
            Store(x => x.ZipCode, Raven.Abstractions.Indexing.FieldStorage.Yes);
        }
 }

I have tried each of the following:
var data = RavenSession.Query<ZipCodesWithAgent.Result, ZipCodesWithAgent>();
var data = RavenSession.Query<ZipCodesWithAgent.Result, ZipCodesWithAgent>().OfType<ZipCodesWithAgent.Result>();

But get:
Unable to cast object of type 'Models.ZipCode' to type 'Result'.

Every time. Any help is appreciated.

Oren Eini (Ayende Rahien)

unread,
Mar 22, 2013, 7:08:50 PM3/22/13
to ravendb
You are using a Map for _indexing_.
Not for storage. It looks like what you want is a transformer, instead.



--
You received this message because you are subscribed to the Google Groups "ravendb" 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/groups/opt_out.
 
 

Kijana Woodard

unread,
Mar 22, 2013, 7:09:59 PM3/22/13
to rav...@googlegroups.com

Scott

unread,
Mar 22, 2013, 7:12:42 PM3/22/13
to rav...@googlegroups.com
Kijana,
I don't see any ProjectFromIndexFieldsInto() method. 

Oren,
I will look in to a transformer.

Kijana Woodard

unread,
Mar 22, 2013, 7:15:00 PM3/22/13
to rav...@googlegroups.com
using Raven.Client;
using Raven.Client.Linq;

Google gave me older docs. I found the current copy:

Scott Scowden

unread,
Mar 22, 2013, 7:16:57 PM3/22/13
to rav...@googlegroups.com
Ugh! Can't believe I did that. I had Raven.Client.Linq, not Raven.Client. That worked, thank you!


--
You received this message because you are subscribed to a topic in the Google Groups "ravendb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/ZmgMTfaWbaA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.

Kijana Woodard

unread,
Mar 22, 2013, 7:17:35 PM3/22/13
to rav...@googlegroups.com
But...a transformer may be better. I didn't notice the LoadDocument before. Not sure how that plays with field Store.

TransformWith is in 2.5 unstable.

Kijana Woodard

unread,
Mar 22, 2013, 7:18:07 PM3/22/13
to rav...@googlegroups.com

Scott

unread,
Mar 22, 2013, 7:53:15 PM3/22/13
to rav...@googlegroups.com
Switched it, thanks!
Reply all
Reply to author
Forward
0 new messages