Cannot understand how to translate Trim()

51 views
Skip to first unread message

Ronald

unread,
May 16, 2012, 9:00:52 AM5/16/12
to ravendb
Hi Guys,

We are getting below exception "Cannot understand how to
translate x.FirmName.Trim()" when we try to filter documents on
FirmName by using a dynamic lambda expression which is used in our
linq query to filter.

Expression<Func<CommunityProject, bool>> func = x =>
x.FirmName.Trim().In(anyArchFirm);

here "anyArchFirm" is list of firm names.

Our goal is to match "xyz" with "xyz ", So is there any work around,
please suggest.

Thanks!
a n sarma

Oren Eini (Ayende Rahien)

unread,
May 16, 2012, 9:23:14 AM5/16/12
to rav...@googlegroups.com
You can't do that in the query, you can trim the value during the indexing:

from x in docs.CommunityProjects
select new { FormName = x.FirmName.Trim() }

Chris Marisic

unread,
May 16, 2012, 9:27:53 AM5/16/12
to rav...@googlegroups.com
You shouldn't be doing that.

You either want to trim your data coming in that you never save the trailing/leading whitepsace.

Past that, if you need to deal with this data in the database you want to use an approiprate lucene analyzer that will will handle this for you. Honestly I think any of the built in analzyers should allow you to search for "xyz" and find "xyz " except for the NotAnalyzed which is meant to store tokens EXACTLY as they are, this is mainly only useful for primary keys / guids.

Nageswara Sarma Aravelli

unread,
May 16, 2012, 10:16:52 AM5/16/12
to rav...@googlegroups.com
Thanks Oren
Reply all
Reply to author
Forward
0 new messages