ppusiol
ppusiol

Reputation: 41

MongoDB Realm in .NET Framework 4.8.1 App

I am working in a WPF based app, and I would like to use Realm as a DB engine for a specific part of the project. I tried installing the packages via Nuget, but for some reason it appears to fail. I believe the problem seems to be related to using .NET Framework instead of newer .NET. Am I right? Is Realm incompatible with .NET Framework 4.8.1?

Update:

Here are the errors after i create a class using IRealmObject interface:

enter image description here

Using latest Realm installed via Nuget and .NET FW 4.8.1

Thanks

Upvotes: 0

Views: 213

Answers (2)

jannisrow
jannisrow

Reputation: 38

In Realm you have two approaches.

  1. Inherit from RealmObject
  2. Declare a partial class implementing the IRealmObject. Partial is necessary because realm runs a source generator adding methods to implement the interface in a seperate partial class.

The Errors shown in the original question are raised probably because the class implementing the IRealmObject is not partial and the source generation of realm fails then. Example for implementing IRealmObject correctly:

    public partial class Exercise : IRealmObject, IEntity<ObjectId>
{

    [PrimaryKey]
    [MapTo("_id")]
    public ObjectId Id { get; set; } = ObjectId.GenerateNewId();

    [MapTo("partition")]
    public string Partition { get; set; } = string.Empty;
}

( IEntity is custom interface that gets implemented)

Upvotes: 1

ppusiol
ppusiol

Reputation: 41

So,

Basically I have an Interface ICalibration, where that interface implements IRealmObject, and my error was in the implementation of such interface. You have to implement RealmObject and latter the ICalibration:

interface ICalibration : IRealmObject { ... }

partial class DualLinearRegressionCalibration : RealmObject, ICalibration {...}

Upvotes: 0

Related Questions