.NET SDK create record Unique Constraint


#1

In teh .NET SDK your create record method passes a 0 for id on all records as this is unknown until teh response comes back with the id’s populated etc

It Seems that the JSON DefaultValueHandling = DefaultValueHandling.Ignore is not working on the freshly minted int ‘0’ id’s

An therefore the body has the id:0 and trys inserts the records with id:0 on all and trips a Unique constraint :frowning:

Will try and see if it is enviromental to my enviroment

YipYip


#2

Dont know whether it is my environment or not :S

I added a conditional Property Serialization attribute to the StaffRecord Poco/DTO

internal class StaffRecord
{

        public bool ShouldSerializeUid()
        {
            return Uid != 0;
        }

        public int Uid { get; set; }

        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
        public bool Active { get; set; }

        public override string ToString()
        {
            return string.Format("{0}: name = {1} {2}, age = {3}, active = {4}", Uid, FirstName, LastName, Age, Active);
        }
    }

This now works as expected on both serialization/deserialization

Here is the docs in teh JSON.NET docs
Conditional Property Serialization

Cheers :smiley: