Skip to content

Commit 792eb3d

Browse files
authored
Merge pull request #741 from appwrite/feat-dotnet-db-models-readme
Add instruction for preparing models in .NET SDK readme
2 parents 8e71ca4 + ba31ef2 commit 792eb3d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

templates/dotnet/README.md.twig

+22-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,31 @@ dotnet add package {{ spec.title | caseUcfirst }} --version {{ sdk.version }}
4545
{{ sdk.gettingStarted|raw }}
4646
{% endif %}
4747

48+
### Preparing Models for Databases API
49+
50+
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.
51+
52+
The way to fix this is to add the `JsonProperty` attribute to the properties in the POCO class you create for your model.
53+
54+
For e.g., if you have two attributes, `name` (`string` type) and `release_date` (`DateTime` type), your POCO class would be created as follows:
55+
56+
```csharp
57+
public class TestModel
58+
{
59+
[JsonProperty("name")]
60+
public string Name { get; set; }
61+
62+
[JsonProperty("release_date")]
63+
public DateTime ReleaseDate { get; set; }
64+
}
65+
```
66+
67+
The `JsonProperty` attribute will ensure that your data object for the Appwrite database is serialized with the correct names.
68+
4869
## Contribution
4970

5071
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.
5172

5273
## License
5374

54-
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.
75+
Please see the [{{spec.licenseName}} license]({{spec.licenseURL}}) file for more information.

0 commit comments

Comments
 (0)