Skip to content

Commit

Permalink
Merge pull request #741 from appwrite/feat-dotnet-db-models-readme
Browse files Browse the repository at this point in the history
Add instruction for preparing models in .NET SDK readme
  • Loading branch information
abnegate authored Nov 9, 2023
2 parents 8e71ca4 + ba31ef2 commit 792eb3d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion templates/dotnet/README.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.

0 comments on commit 792eb3d

Please sign in to comment.