Skip to content
Discussion options

You must be logged in to vote

You could also use automapper or a similar library and define a mapping rule that sets only a subset of all properties. Then, instead of doing an upsert, you'd need to lookup the existing object and map on top of it. In pseudocode, would look something like:

var second = new MyObject { ... };
realm.Write(() =>
{
    var existing = realm.Find<MyObject>(second.Id);
    if (existing == null)
    {
        realm.Add(second);
    }
    else
    {
        // this uses some predefined mapping rule that will
        // set Count, but not SomeLocalState
        mapper.Map(second, existing);
    }
});

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tschbc
Comment options

@nirinchev
Comment options

Answer selected by tschbc
@tschbc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants