Raven4 : Querying index error

248 views
Skip to first unread message

Dejan Miličić

unread,
Jun 17, 2017, 12:34:12 PM6/17/17
to RavenDB - 2nd generation document database
I am trying to convert code that is already working with 3.5 to version 4. This method

        public List<string> GetCorrespondents(IDocumentSession session, User user)
        {
            return session.Query<CorrespondentsPerUser.Result, CorrespondentsPerUser.Index>()
                .Where(x => x.UserId == user.Id)
                .OrderByDescending(x => x.Cardinality).ThenByDescending(x => x.Timestamp)
                .Select(a => a.CorrespondentId)
                .ToList();
        }

generates this exception

TargetException: Non-static method requires a target.

  • System.Reflection.RuntimeMethodInfo.CheckConsistency(object target)

  • System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

  • System.Reflection.RuntimeMethodInfo.Invoke(object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

  • System.Reflection.RuntimePropertyInfo.GetValue(object obj, Object[] index)

  • Raven.Client.Documents.Linq.LinqPathProvider.GetValueFromExpressionWithoutConversion(Expression expression, out object value)

  • Raven.Client.Documents.Linq.LinqPathProvider.GetValueFromExpression(Expression expression, Type type)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitEquals(BinaryExpression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitQueryableMethodCall(MethodCallExpression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitMethodCall(MethodCallExpression expression, bool negated)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitQueryableMethodCall(MethodCallExpression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitMethodCall(MethodCallExpression expression, bool negated)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitQueryableMethodCall(MethodCallExpression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitMethodCall(MethodCallExpression expression, bool negated)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitQueryableMethodCall(MethodCallExpression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.VisitMethodCall(MethodCallExpression expression, bool negated)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.GetDocumentQueryFor(Expression expression)

  • Raven.Client.Documents.Linq.RavenQueryProviderProcessor.Execute(Expression expression)

  • Raven.Client.Documents.Linq.RavenQueryInspector.GetEnumerator()

  • System.Collections.Generic.List..ctor(IEnumerable<T> collection)

  • System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)


However, if I comment out "Where" like this

        public List<string> GetCorrespondents(IDocumentSession session, User user)
        {
            return session.Query<CorrespondentsPerUser.Result, CorrespondentsPerUser.Index>()
                //.Where(x => x.UserId == user.Id)
                .OrderByDescending(x => x.Cardinality).ThenByDescending(x => x.Timestamp)
                .Select(a => a.CorrespondentId)
                .ToList();
        }

I receive no exception

Probably important info is that this happens when application is started, so there are no documents that are indexed by this index, and as a result of that, index is empty

Michael Yarichuk

unread,
Jun 18, 2017, 6:23:05 AM6/18/17
to RavenDB - 2nd generation document database
Hi,
I will take a look at this.
Can you post index and entity definitions that are used here?

Also, is it possible to reproduce this in unit test?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Best regards,

 

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Michael Yarichuk l RavenDB Core Team 

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

 

RavenDB paving the way to "Data Made Simple"   http://ravendb.net/  

Dejan Miličić

unread,
Jun 19, 2017, 3:23:46 AM6/19/17
to RavenDB - 2nd generation document database
After I did not manage to reproduce problem with unit test, I realized cause of this is in my code and completely unrelated to Raven4.
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.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2017, 3:28:35 AM6/19/17
to ravendb
Okay, can you explain what happened, we might be able to give a better error

Hibernating Rhinos Ltd  

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

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Dejan Miličić

unread,
Jun 19, 2017, 3:46:38 AM6/19/17
to RavenDB - 2nd generation document database
My application is using MediatR (https://github.com/jbogard/MediatR) and Hangfire with RavenDB persistence (https://github.com/RefreshingIO/hangfire-ravendb)
After upgrading Ravendb client to version 4, Hangfire.RavenDB stopped working since it is not yet supporting Raven4.
Instead of uninstalling Hangfire nuget package, I commented out all calls, but I missed one, which was not giving any visible exceptions but resulted in non of Mediatr handlers being registered.
And that was the cause of the problem.
Once I removed Hangfire nuget package everything was working again.

I will probably update Hangfire.Raven4 to new version when I catch some time.

However, just like last time I tried Raven4, I have one blocker that is preventing me from switching to Raven4.

store.Conventions.CustomizeJsonSerializer += serializer => serializer.Converters.Add(new JsonNodaMoneyConverter());

This custom converter is never called at all. One of the classes in the project has property of type NodaMoney, and this serializer should be triggered for it, but when I debug, it is simply not invoked.
Could it be because NodaMoney is struct?

Oren Eini (Ayende Rahien)

unread,
Jun 20, 2017, 2:36:53 PM6/20/17
to ravendb
Hm.. that should work 

Are you calling this _after_ the store has been initialized?
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Dejan Miličić

unread,
Jun 20, 2017, 8:03:05 PM6/20/17
to RavenDB - 2nd generation document database
Here is how I do it

        private static IDocumentStore CreateStore()
        {
            var store = new DocumentStore();
            store.Urls = new string[] {Url};
            store.Database = DatabaseName;

            store.Conventions.CustomizeJsonSerializer += serializer => serializer.Converters.Add(new JsonNodaMoneyConverter());
            store.Initialize();

            return store;

Oren Eini (Ayende Rahien)

unread,
Jun 21, 2017, 2:02:52 AM6/21/17
to ravendb
Can you send us the full test case? I tried with the attached code, and it seems to be working:

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Program.cs
Reply all
Reply to author
Forward
0 new messages