Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Nullable properties in Realm objects (DateTime more exactly)?

The question is really simple, about how to workaround this error:

Fody/RealmWeaver: class 'X' field 'Y' is a 'System.Nullable`1' which is not yet supported.

This is for a DateTime? property. Nullable primitive types are indeed supported.

I know the Java version supports null values. This is about Realm .NET. I was wondering if there's any other way besides doing the old DateTime SomeNullableProperty & bool HasSomeNullableProperty thing.

like image 986
Marcel N. Avatar asked Jul 07 '16 00:07

Marcel N.


2 Answers

We implement the standard optional properaties such as int? and bool? for primitives. This is briefly mentioned in our docs under optional properties

Reference types such as String can be null.

We also support the optional value type DateTimeOffset?.

See the full list in the AccessTests.cs

like image 95
Andy Dent Avatar answered Oct 07 '22 18:10

Andy Dent


Your best option is to add a boolean field for every field you want to allow nullability.

like image 38
Pieter de Vries Avatar answered Oct 07 '22 19:10

Pieter de Vries