Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison to null in Filter expression #203

Closed
jonorossi opened this issue Apr 14, 2015 · 6 comments
Closed

Comparison to null in Filter expression #203

jonorossi opened this issue Apr 14, 2015 · 6 comments

Comments

@jonorossi
Copy link
Collaborator

At first I thought rethinkdb-net didn't support Nullable<DateTime> inside a Filter() expression, so I tried both x == null and x.HasValue, both didn't work, then I tried with a string and that also didn't work. Following is the ReQL query and the C# I'm trying to use, I just get back an empty enumerable without anything matching:

ReQL:

r.db('mydb').table('mytable')
  .filter({my_string: null})

C#:

Query.Db("mydb").Table<MyClass>("mytable")
    .Filter(r => r.my_string == null)
);

I had a look through the source code to work out how I'd fix this, but I'm quite lost and I suspect this fix is going to be quite involved. Any chance you've got some time to fix it or point me in the right direction? Thanks.

@mfenniak
Copy link
Owner

I've written some unit tests in a branch, PR #204. Oddly, I can't get the behavior that you see where you get back an empty enumerable. I created three test cases with two variations:

  • A Nullable<T> value filtered on o.Value_Int_Nullable == null and o.Value_Int_Nullable != null. This seemed to work without any changes.
  • A Nullable<T> value filtered with !o.Value_Int_Nullable.HasValue and o.Value_Int_Nullable.HasValue. This did not work; it threw an error. I've fixed this one in the PR currently.
  • A nullable field (string) filtered with o.Name == null and o.Name != null. This doesn't work, but throws an error. This one might be weird to fix, but it obviously makes sense, so I'll see what I can do.

I've only had errors where the code won't work at all. None of them worked but caused no results to return. Would you mind taking a look at my tests and see if they represent the situation you're running into?

@jonorossi
Copy link
Collaborator Author

I'm not sure what Nancy is doing, but just throwing back the RethinkDb.SynchronousApiExtensions+AsyncEnumerableSynchronizer<MyModel> must be swallowing the exception. Explicitly calling ToList() throws a System.NotSupportedException: Datum converter is not available for type System.Object, which I remember seeing when I was building up a bigger query outside of the Nancy module which I couldn't get to compile.

Many thanks for looking at this so quickly, sorry for sending you on a wild goose chase.

@mfenniak
Copy link
Owner

Great; the System.NotSupportedException: Datum converter is not available for type System.Object error is the same that I've got for the third test case. I'll have that fixed shortly.

@mfenniak
Copy link
Owner

I believe this issue is fixed in the issue_203 branch. If you have the time, could you take a look and verify before I merge that branch? :-)

@jonorossi
Copy link
Collaborator Author

Many thanks Mathieu. I just tested your changes and they work for me.

I can see the fix is not quite obvious, but I'm getting a better idea of how this library and rethinkdb communicate.

@mfenniak
Copy link
Owner

Thanks for the issue report, and the other PRs you submitted. I love having new contributors to this project. :-) Let me know if there's anything I can do to help you understand and participate in the project more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants