Using Automapper to map object to realm object with Xamarin and c#
<p>I am creating an <code>Xamarin.iOS</code> app and a <code>Realm</code> database.I would like to keep my <code>POCO</code> objects separate from my <code>RealmObject</code> so what I did was use a repository pattern and within the repository I tried to use AutoMapper to map the POCO to the <code>RealmObject</code></p>

<p>e.g. (subset)</p>

<pre class="lang-cs prettyprint-override"><code>public class PlaceRepository : IPlaceRepository
{
    private Realm _realm;

    public PlaceRepository(RealmConfiguration config)
    {
        _realm = Realm.GetInstance(config);
    }

    public void Add(Place place)
    {
        using (var trans = _realm.BeginWrite())
        {
            var placeRealm = _realm.CreateObject&lt;PlaceRealm&gt;();
            placeRealm = Mapper.Map&lt;Place, PlaceRealm&gt;(place);

            trans.Commit();
        }
    }
</code></pre>

<p>So, if I debug my code everything maps OK and placeRealm is populated OK but when I commit nothing gets saved to the Realm db. The following is my <code>RealmObject</code></p>

<pre class="lang-cs prettyprint-override"><code>public class PlaceRealm : RealmObject
{
    [ObjectId]
    public string Guid { get; set; }
    public string Title { get; set; }
    public string Notes { get; set; }
 }
</code></pre>

<p>and this is my POCO Place</p>

<pre class="lang-cs prettyprint-override"><code>public class Place
{
    public string Guid { get; set; }
    public string Title { get; set; }
    public string Notes { get; set; }
 }
</code></pre>

<p>And AutoMapper is initialized like so:</p>

<pre class="lang-cs prettyprint-override"><code> Mapper.Initialize(cfg =&gt;
 {
      cfg.CreateMap&lt;Place, PlaceRealm&gt;();
      cfg.CreateMap&lt;PlaceRealm, Place&gt;();
  });
</code></pre>

<p>All standard stuff. Has anyone else managed to get something similar working?</p>