Realm .NET string primary key is optional

I have an iOS app written in Swift, that is using a full sync Realm stored in Realm Cloud.

When I look at the class “FullUser” in Realm Studio it looks like this:

uuid string (Primary Key)   
Id   int   
name string

I have also a .net class on the server that will access the same Realm.

C# code of class, (somewhat shortened):

    public class FullUser : RealmObject
    public string Uuid { get; set; }

    public int Id { get; set; }

    public string Name { get; set; }

When I try to do a full sync in .net, I get error message:

ERROR: Connection[1]: Session[1]:
Failed to transform received changeset: Schema mismatch:
‘FullUser’ has primary key ‘uuid’, which is nullable on one side,
but not the other.

If I then look at my newly created, local synced Realm-file it looks like this:

uuid string? (Primary Key)   
Id   int   
name string?

For some reason, when I sync the Realm in .net
it makes the string properties optional in my local Realm.

How do I specify that I want my C#-code to create the string as
non nullable in my local Realm so it matches the one in the server so they can sync?

Strings are implicitly nullable in .NET. If you want to make them non-nullable in the database, you should annotate the property with [Required].

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.