Comments (8)
@redplane problem could be upsert search expression:
new Account() {Email = insert.Email}
serialize to
{ Email: "[email protected]", FirstName: null, LastName: null }
Since this expression will never found a document, then insert will occur and you get unique constraint violated
because you have unique hash index on Email
One solution is to ignore null members by:
public class Account
{
public string Email { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string FirstName { get; set; }
}
Another solution is to use an anonymous object for search expression:
arangoDatabase.Query()
.Upsert(_ => new Account() {Email = insert.Email}
// should be
arangoDatabase.Query()
.Upsert(_ => new {Email = insert.Email}
from arangoclient.net.
Sorry, I forgot importing my model class. Here it is :
public class Account
{
[DocumentProperty(Identifier = IdentifierType.Key)]
public string Email { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string FirstName { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
}
By the way, I used anonymous object as your guide, but still failed
Here is my screenshot.
http://i.imgur.com/D0jw7I3.png
from arangoclient.net.
@redplane for the first solution(JsonProperty
on Account
), do you use ArangoDB.Client.Common.EmbeddedNewtonsoft.Json.JsonProperty
attribute on class members? if yes you should use Newtonsoft.Json.JsonProperty
.
and second solution(anonymous object) should work too, since you specify Email
as IdentifierType.Key
, member name will serialize to _key
. so the upsert search expression should change to:
arangoDatabase.Query()
.Upsert(_ => new { _key = insert.Email }
this is because client could not resolve anonymous object members to the correct name (here it cant resolve Email
to _key
).
from arangoclient.net.
The second solution worked :)
arangoDatabase.Query() .Upsert(_ => new { _key = insert.Email }
I think you should change the example code of Linq folder, because I copied code from that example :)
Thank you for your help :). I think this issue can be closed.
from arangoclient.net.
@redplane first solution should work too, sorry but could you check if you use ArangoDB.Client.Common.EmbeddedNewtonsoft.Json.JsonProperty
or Newtonsoft.Json.JsonProperty
attribute on class members?
from arangoclient.net.
After checking these 2 solutions you gave me. Here is my conclusion:
- The first one works when no key is specified in my Model. That means my model should be:
public class Account
{
/// <summary>
/// Account email.
/// </summary>
public string Email { get; set; }
/// <summary>
/// Account first name.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string FirstName { get; set; }
/// <summary>
/// Account last name.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
}
And the function I'll use for upsert is :
arangoDatabase.Query() .Upsert(_ => new Account() {Email = insert.Email}
- The second one works when I set a property as a key in my model. Here is my model in this case:
public class Account
{
/// <summary>
/// Account email.
/// </summary>
[DocumentProperty(Identifier = IdentifierType.Key)]
public string Email { get; set; }
/// <summary>
/// Account first name.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string FirstName { get; set; }
/// <summary>
/// Account last name.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
}
And the upsert function I used was :
arangoDatabase.Query() .Upsert(_ => new { _key = insert.Email }
Thank you for these solutions :). You saved my day.
from arangoclient.net.
@redplane your welcome, first solution should work too, i tested it my self, can you provide a failing test please?
from arangoclient.net.
I tested my app again, the 1st solution worked :D.
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Thread safety HOT 7
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
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 arangoclient.net.