5

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.

Marcel N.
  • 13,726
  • 5
  • 47
  • 72

2 Answers2

6

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

Andy Dent
  • 17,578
  • 6
  • 88
  • 115
  • Thanks, Andy. I was actually trying with a `DateTime?` (value type) and got that error. Is this supported as well? – Marcel N. Jul 07 '16 at 10:21
  • No, if you had tried just a straight DateTime you would have got the error saying we only support DateTimeOffset. https://blogs.msdn.microsoft.com/davidrickard/2012/04/06/datetime-and-datetimeoffset-in-net-good-practices-and-common-pitfalls/ is a good explanation why. – Andy Dent Jul 07 '16 at 10:55
  • Yes, no `DateTime?` support yet. I'll create an issue in GitHub. – Marcel N. Jul 07 '16 at 10:55
  • Thanks for the link. Maybe it's worth switching. – Marcel N. Jul 07 '16 at 10:57
2

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

Pieter de Vries
  • 825
  • 7
  • 18