Query using generic type gives error "Cannot understand how to translate method 'GetValue'

77 views
Skip to first unread message

Bob Lamb

unread,
Dec 30, 2020, 7:52:42 AM12/30/20
to RavenDB - 2nd generation document database
simple query using generic type

 _dbSession.Query<T>().Search(x => x.GetType().GetProperty("Name").GetValue(x),"a");

Gives error
  System.NotSupportedException: Could not understand expression: Convert(from 'Operators', IRavenQueryable`1).Search(x => x.GetType().GetProperty("Name").GetValue(x, null), "a", 1, Guess, Or)
       ---> System.NotSupportedException: Cannot understand how to translate method 'GetValue' of 'System.Reflection.PropertyInfo' type. x.GetType().GetProperty("Name").GetValue(x, null)


     

Oren Eini (Ayende Rahien)

unread,
Dec 30, 2020, 8:53:13 AM12/30/20
to ravendb
You cannot issue a query like that using Linq.
You can use the _dbSession.Advanced.DocumentQuery<T>().WhereEquals("Name","a"); instead

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/a8c8e9ec-e95e-4b66-941e-61c1ebf7ab8en%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  

Bob Lamb

unread,
Dec 30, 2020, 11:35:26 AM12/30/20
to RavenDB - 2nd generation document database

thanks for the quick response as always
Reply all
Reply to author
Forward
0 new messages