IDocumentQuery SetResultTransformer is not working

53 views
Skip to first unread message

Nima Ha

unread,
Sep 23, 2014, 7:33:54 AM9/23/14
to rav...@googlegroups.com
According to this post :

We can use Query.Customize to get the IDocumentQuery and set a result transformer for a transformer that has no equivalent type in our client
Well I have another problem and that's the generic argument of IDocumentQuery is itself a type that's compiled at runtime so I have to use reflection here's what I do :

query.Customize( x =>
            {
                var type = x.GetType();
                var method = type.GetMethod("SetResultTransformer");
                method.Invoke(x, new object[] {typename + "Transformer"});
            });
 
Although I can see that the non public field of DocumentQuery is set to typename + "Transformer" using this method but unfortunately it doesn't have any effect on the request (no ResultTransformer is added to the Url) and thus I am getting an error that the return type is not the same as type expected. 
Am I doing something wrong ? 

Oren Eini (Ayende Rahien)

unread,
Sep 23, 2014, 7:37:19 AM9/23/14
to ravendb
Takes a lot of steps back first.
What is it that you are trying to do?

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.

Nima Ha

unread,
Sep 23, 2014, 7:52:54 AM9/23/14
to rav...@googlegroups.com
We have two types that are generated in run time one is used as our document schema and the other one is used for searching our documents.
 (Each document has so many fields like 200 to 300 fields.)
I have created an Index and a Transformer to be able to search our documents and return its result in our format.
Both of them is created using Store.DatabaseCommands (PutIndex,PutTransformer)
I wrote a function that uses dynamic linq library to query an index for me :

Something like this :

var query=RavenSession.Query<T>(typeof (T).Name + "Index")
                .Statistics(out statistics)
                .Customize(x => x.WaitForNonStaleResults()).Where(filter)
                .OrderBy(sortCommand)
                .SetPaging(pagingInfo);

filter and sortcommands are string.

Since this function is generic too , I am calling it using reflection to be able to pass my SearchType as T then I call :

query.Customize( x =>
            {
                var type = x.GetType();
                var method = type.GetMethod("SetResultTransformer");
                method.Invoke(x, new object[] {typename + "Transformer"});
            });

at some other part of my code (I have a dictionary to inject a customization function for suitable types)

I don't get any errors but no ResultTrasnformer is added to URL and thus no transformation takes place


Oren Eini (Ayende Rahien)

unread,
Sep 23, 2014, 8:09:24 AM9/23/14
to ravendb
  .Customize(x => 
{
   x.WaitForNonStaleResults();
   ((IDocumentQuery<T>)x).SetResultTransformer("foo")

}).Where(filter)


A) why are you using runtime generated types?
B) why not use TransformWith(string) overload?


Hibernating Rhinos Ltd  

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

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

 


Nima Ha

unread,
Sep 23, 2014, 8:25:03 AM9/23/14
to rav...@googlegroups.com
A) Well It's somehow a legacy system I am not in charge so I can't change its structure 
B)I can't see any  TransformWith(string) overload ? Do I have to add another dll ? I am using Raven.Client.LightWeight 2.5

Oren Eini (Ayende Rahien)

unread,
Sep 23, 2014, 8:27:19 AM9/23/14
to ravendb
Make sure you have using Raven.Client.Linq

Hibernating Rhinos Ltd  

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

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

 


On Tue, Sep 23, 2014 at 3:25 PM, Nima Ha <hamid...@gmail.com> wrote:
A) Well It's somehow a legacy system I am not in charge so I can't change its structure 
B)I can't see any  TransformWith(string) overload ? Do I have to add another dll ? I am using Raven.Client.LightWeight 2.5

--

Nima Ha

unread,
Sep 23, 2014, 8:39:59 AM9/23/14
to rav...@googlegroups.com
I am using Raven.Client.Linq but there's no overload for TransformWith that takes string . I am using  RavenDB.Client.2.5.2916 package.
Anyway I did as you said (to have all customization in one place) and  I checked my query object but I noticed that ResultTransformer of QueryProvider object is null.


Oren Eini (Ayende Rahien)

unread,
Sep 23, 2014, 8:48:11 AM9/23/14
to ravendb
Oh, sorry, that is a 3.0 construct.

Hibernating Rhinos Ltd  

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

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

 


On Tue, Sep 23, 2014 at 3:39 PM, Nima Ha <hamid...@gmail.com> wrote:
I am using Raven.Client.Linq but there's no overload for TransformWith that takes string . I am using  RavenDB.Client.2.5.2916 package.
Anyway I did as you said (to have all customization in one place) and  I checked my query object but I noticed that ResultTransformer of QueryProvider object is null.


Reply all
Reply to author
Forward
0 new messages