mfenniak / rethinkdb-net

A C# / .NET client driver for RethinkDB.
Other
247 stars 37 forks source link

Exception when using client-side get-only member of type List<T> in filter expression #220

Closed sceee closed 8 years ago

sceee commented 9 years ago

When making a query like

IEnumerable<MyDTO> query = DatabaseConnection.Run(DB.Table<MyDTO>("tablename").Filter(dto => someotherdto.MyStringList.Contains(dto.SomeString)));
            List<MyDTO> result = query.ToList();

I receive the following exception in BaseExpression ServerSideMemberAccess(..)

Additional information: Member MyStringList on type System.Collections.Generic.List`1[System.String] could not be mapped to a datum field

Please note the "someotherdto" contains a get only field MyStringList of type List. This is not attributed with [DataMember]. The MyDTO contains a property SomeString which is attributed with [DataMember].

It seems similar to the issue I reported once ( https://github.com/mfenniak/rethinkdb-net/issues/196 ) and the query worked until I updated to the latest rethinkdb-net (and rethinkdb) version yesterday.

mfenniak commented 9 years ago

My guess would be that PR #209 would have broken this. Before that change, someotherdto.MyStringList would have been evaluated client-side and the resulting array sent to RethinkDB. In a post-#209 world, someotherdto appears to be an object that we can access fields on, so we'd attempt to evaluate it server-side, and then convert the entire someotherdto object to it's server-side representation as well.

An easy fix for you would be to change line 232 in BaseExpression.cs to "return false;". That should revert to attempting client-side evaluation of that portion of the expression because the field can't be mapped. Can you try that out in your specific use-case and ensure it works? If it does, I'll patch that in to the next release. It's not the best fix, but it seems like it would work.

sceee commented 9 years ago

Thank you Mathieu, the "return false;" fix in line 232 in BaseExpression.cs works and fixes my issue.