Realm . NET - Create object copy

Asked

Viewed 53 times

0

Guys I’m having trouble using Realm, in . NET with Xamarin.

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

My method should open Remake, query the object and return that object so I can work outside the data layer.

Even using Deepcloner (nuget), Realm keeps giving an Exception saying that the Realm is closed, but it’s even because I’m using, as the documentation suggests.

It is possible to make a copy of the Realm object before closing it so that I can work the data on the top layer. This data will be read-only and I won’t change it, just read it.

Code that the method makes.

using(var realm = Realm.GetInstance(config))
{
    var data = realm.All<DadosUsuario>().FirstOrDefault().ShallowCopy();
}

1 answer

0

With the help of Soen and the user @Sushihangover of the same, he wrote a library where it has an extension method called Nonmanagedcopy.

This method makes the writing flat of the object and returns the same of the Realm, not having the responsibilities of it and being able to use in an untitled form of the Realm.

The excerpt from my code looked like this:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.