Comments (4)
I think function should return res.Data[0].ToObject<T>();
, not the (T)(object)res.Data[0];
from rethinkdb.driver.
So complicated. I tried to repeat this code with boxing/unboxing, converting to jobject and back. But ids equals anyway.
from rethinkdb.driver.
Oh. Seems like i understood wrong this function... Insert method wouldn't return object. But why i get default(T)?
from rethinkdb.driver.
Hi Dmitriy,
You need to use .RunWrite(conn)
instead. Please be confident that you see a problem in the driver source code before posting a GitHub issue for help. Supposing a problem exists is not sufficient for posting issues. If you think you might need help, please use the public help Slack and Discord channels.
The code in the driver that you referenced above is correct.
The only time (T)(object)res.Data[0];
is called is if T
is typeof(T).IsJToken()
; and in this case, T
is State
not a JObject
/JArray
/JValue
/JToken
.
Because T
is State
the code res.Data[0].ToObject<T>(Converter.Serializer);
is executed as expected.
The reason you are receiving an empty State
object that looks like default(T)
is that you're deserializing JSON response data with the wrong type of T
.
For example, this is what you're doing:
public class ServerWriteResponse{
public int Inserted {get;set;}
public int Deleted {get;set;}
}
public class State{
public string SomeProperty {get;set;}
public string Id {get;set;}
}
The response from for the table.Insert(state)
is:
{
"inserted": 1,
"deleted": 0
}
Effectively, when you specify .RunAtom<State>(conn)
you are saying to the driver the following:
JsonConvert.Deseralize<State>("{'inserted':1,'deleted':0}").Id != state.Id
The code above does not make any sense because the JSON insert response does not match State
type. This is why you get an object that looks like default(T)
. The JSON data does not match the type T
specified.
The correct usage is as follows:
[TestFixture]
public class Issue147
{
public class State
{
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Id { get; set; }
public string someProperty { get; set; }
protected internal State()
{
this.Id = Guid.NewGuid().ToString();
}
[JsonConstructor]
public State(string someProperty)
{
}
}
[Test]
public void Test()
{
var conn = R.Connection().Connect();
var s = new State();
var table = R.Db("query").Table("test");
var result = table.Insert(s).RunWrite(conn);
result.Inserted.Should().Be(1);
}
}
Please remember, if you don't have 100% confidence there is an issue with driver code, please ask for help in the chat channels. I will try to answer any questions you have when I have time.
Thanks,
Brian Chavez
from rethinkdb.driver.
Related Issues (20)
- Create a method to return result as raw json HOT 4
- Resolution function on OptArg insert conflict HOT 1
- ConnectionPool.Builder.ConnectAsync does not respect InitialTimeout() HOT 4
- Add Error codes to Exceptions HOT 2
- Additional exceptions thrown when trying to cancel Cursor.MoveNextAsync() HOT 6
- Support for System.Text.Json.JsonDocument
- Cursor<T> should implement IAsyncEnumerable<T> in .net core 3
- RethinkDB 2.4 Release
- Best options: RunResult, RunAtom or RunCursor HOT 3
- Get list from Table that contains 'A' in the 'message' field HOT 1
- ASL 2.0 HOT 1
- Implement lambda functions as a possible argument in Insert().OptArgs("conflict",...) HOT 1
- System.NullReferenceException HOT 1
- Add EntityFramework support to Linq provider HOT 5
- Polymorphism HOT 1
- Various exceptions when updating a document HOT 1
- System.Configuration.ConfigurationErrorsException: HOT 1
- Wrong OptArg serialisation after OrderBy
- Insert not working with RunNoReply & Can't use runOpts is always null -- solved
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinkdb.driver.