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
77 stars 30 forks source link

How to map arangodb attributes to C# properties #478

Closed mselite closed 1 year ago

mselite commented 1 year 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 1 year 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 1 year ago

Thanks @DiscoPYF for your help.

DiscoPYF commented 1 year 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.