Realm .NET - Create object copy

0

I'm having problems using Realm in .NET with Xamarin.

I can usually add, update, or delete objects from a Realm. But as the pro version .NET does not have a copyFromRealm, here comes my doubt.

My method should open the realm, query the object and return that object to work outside the data layer.

Even though I'm using DeepCloner (nuget), Realm gives me an exception saying that Realm is closed, but it's because I'm using using, as the documentation suggests.

Is it possible for me to make a copy of the Realm object before closing it so that I can work the data in the top layer. These data will be read-only and I will not change them, just read them.

Code that the method does.

using(var realm = Realm.GetInstance(config))
{
    var data = realm.All<DadosUsuario>().FirstOrDefault().ShallowCopy();
}
    
asked by anonymous 18.12.2017 / 20:15

1 answer

0

With the help of SOen and the @SushiHangover user of it, he wrote an biblioteca where you have an extension method called NonManagedCopy.

This method does the flat writing of the object and returns the same of Realm, not having the responsibilities of the same one and being able to use in an unattached form of Realm.

The snippet of my code looks like this:

using (var realm = Realm.GetInstance(config))
{
    return realm.All<DadosUsuario>().FirstOrDefault().NonManagedCopy<DadosUsuario>();
}
    
19.12.2017 / 14:27