From ba31ef251f7798e668f0c7518bed8c3335165256 Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Thu, 9 Nov 2023 20:34:47 +0530 Subject: [PATCH] Add instruction for preparing models for databases API --- templates/dotnet/README.md.twig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/templates/dotnet/README.md.twig b/templates/dotnet/README.md.twig index 8315cd5fc..86b47f298 100644 --- a/templates/dotnet/README.md.twig +++ b/templates/dotnet/README.md.twig @@ -45,10 +45,31 @@ dotnet add package {{ spec.title | caseUcfirst }} --version {{ sdk.version }} {{ sdk.gettingStarted|raw }} {% endif %} +### Preparing Models for Databases API + +For the .NET SDK, we use the `Newtonsoft.Json` library for serialization/deserialization support. The default behavior converts property names from `PascalCase` to `camelCase` on serializing to JSON. In case the names of attributes in your Appwrite collection are not created in `camelCase`, this serializer behavior can cause errors due to mismatches in the names in the serialized JSON and the actual attribute names in your collection. + +The way to fix this is to add the `JsonProperty` attribute to the properties in the POCO class you create for your model. + +For e.g., if you have two attributes, `name` (`string` type) and `release_date` (`DateTime` type), your POCO class would be created as follows: + +```csharp +public class TestModel +{ + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("release_date")] + public DateTime ReleaseDate { get; set; } +} +``` + +The `JsonProperty` attribute will ensure that your data object for the Appwrite database is serialized with the correct names. + ## Contribution This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. ## License -Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information. \ No newline at end of file +Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.