ArangoDB-Community / arangodb-net-standard

A consistent, comprehensive, minimal interface to enable .NET applications to use the complete range of features exposed by the ArangoDB REST API.
Apache License 2.0
76 stars 29 forks source link

How to map arangodb attributes to C# properties #478

Closed mselite closed 10 months ago

mselite commented 10 months ago

I would like to map my arangodb entities to my C# properties, as I am doing it with mongodb, but it didn't work. I am using Json seraialization library to do that. Here is an example:

public class User {
        public class User(string name, string dob) {
        Name = name;
        DoB = dob;
    }
    [JsonPropertyName("name")]
    public string Name { get; set; }

    [JsonPropertyName("dob")]
    public string DoB {get; set;}
}

Any one can help me? Thanks a lot.

DiscoPYF commented 10 months ago

Hi @mselite , JsonPropertyName is a property that is recognized by System.Text.Json serializer.

The default serializer used by ArangoDBNetStandard is Json.NET (Newtonsoft.Json).

You can use JsonProperty to map ArangoDB attributes to C# properties. Example:

public class User
{
    [JsonProperty("_id")]
    public string Id { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("dob")]
    public string DoB { get; set; }
}

I hope this helps.

mselite commented 10 months ago

Thanks @DiscoPYF for your help.

DiscoPYF commented 10 months ago

Happy to help 👍

I will close this issue now that your question is resolved. Feel free to open a new one if anything is not working as expected.