Giter VIP home page Giter VIP logo

Comments (8)

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

redplane avatar redplane commented on May 31, 2024

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.

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

redplane avatar redplane commented on May 31, 2024

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.

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

redplane avatar redplane commented on May 31, 2024

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.

ra0o0f avatar ra0o0f commented on May 31, 2024

@redplane your welcome, first solution should work too, i tested it my self, can you provide a failing test please?

from arangoclient.net.

redplane avatar redplane commented on May 31, 2024

I tested my app again, the 1st solution worked :D.

from arangoclient.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.