bchavez / RethinkDb.Driver

:headphones: A NoSQL C#/.NET RethinkDB database driver with 100% ReQL API coverage.
http://rethinkdb.com/api/java
Other
384 stars 134 forks source link

$reql_type$ not converted when the result is an array. #65

Closed oliverjanik closed 8 years ago

oliverjanik commented 8 years ago

This is a continuation from #39.

Using the latest stable 2.3.3 the second pass for JObject is performed when I do:

Table().Get().RunAtomAsync<JObject>(Conn)

I get correct display like this:

{
  "_createdBy": "oliver",
  "_storedAt": "2016-05-25T01:46:20.436+00:00",
  "id": "3ef139be-5f85-490d-b9bc-402c42945290",
  "test": "hello!"
}

However when I ask for an IEnumerable of JObjects the conversion is not performed:

Table().RunAtomAsync<IEnumerable<JObject>>(Conn)

This returns:

[
  {
    "_createdBy": "oliver",
    "_storedAt": {
      "$reql_type$": "TIME",
      "epoch_time": 1464140780.436,
      "timezone": "+00:00"
    },
    "id": "3ef139be-5f85-490d-b9bc-402c42945290",
    "test": "hello!"
  },
  ...
]

It looks like JObject is special cased somewhere. I'm wandering what happens If I ask for IDictionary<string, JObject>. I've tried plain object and the second pass conversion does not happen either.

I'm using RethinkDB fully dynamically. I don't have classes for my data. That's the main reason I picked RethinkDB. My queries are composed of ReqlExpr on the fly. Is this a use case you want to fully support in this driver? Sorry for creating headaches for you.

bchavez commented 8 years ago

In RunAtomAsync<T>, T is IEumerable. IEnumerable is not JToken type. So, it won't be converted using the 2nd-pass converter. You'll need to ask for T as JArray (RunAtomAsync<JArray>) which derives from JToken and pick off the JObjects from within the JArray.

:last_quarter_moon: :last_quartermoon: [**"Uh huh, you know what it is. Black and yellow..."**_](https://www.youtube.com/watch?v=nWAGLkyxQG0)

oliverjanik commented 8 years ago

Works beautifully. Thanks again.