title: Saving Object Pattern - 1to1 relationship - Entity Framework
body: <p>I work on an ASP .Net MVC 5 project with EntityFramework. I'm quite new on these frameworks.</p>
  
  <p>I've 2 classes bound with a one-to-one relationship :</p>
  
  <p>First class : <strong>Address</strong></p>
  
  <pre><code> public class Address
  {
      public int Id { get; set; }
      public string StreetAddress { get; set; }
      public string PostCode { get; set; }
      public string City { get; set; }
      public string Country { get; set; }
  
      public virtual Meeting Meeting { get; set; }
  
      public virtual double Latitude { get; set; }
      public virtual double Longitude { get; set; }
  
  
      /// &lt;summary&gt;
      /// Returns whole address as a string
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public string ToString()
      {
          return StreetAddress + " " + PostCode + " " + City + ", " + Country;
      }
  
  }
  </code></pre>
  
  <p>Second class : <strong>Meeting</strong></p>
  
  <pre><code>public class Meeting
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public DateTime Date { get; set; }
      public virtual Address Address { get; set; }
  }
  </code></pre>
  
  <p>The Meeting Class is responsible for the relationship, which means I've written a <strong>MeetingService</strong> class to deal with simple CRUD operations. Here's the interface :</p>
  
  <pre><code>public interface IMeetingService
  {
      IEnumerable&lt;Meeting&gt; GetMeetings();
      IEnumerable&lt;Meeting&gt; GetMeetings(int sellerId);
      Meeting GetMeeting(int id);
      void CreateMeeting(Meeting Meeting);
      void EditMeeting(Meeting MeetingToEdit);
      void DeleteMeeting(int id);
      void SaveMeeting();
  }
  </code></pre>
  
  <p>My problem is that I've programmed a reverse geocoding function that updates the Latitude and Longitude fields on the Address Object (with Google MapsApi) and I'm a bit lost on where to call that function.</p>
  
  <pre><code>static void UpdateAdressCoordinates(ref Address address);
  </code></pre>
  
  <p>My first bet was to add some kind of trigger on the setters of the Address Properties and update the Lat/Lng each time other fields are modified but it feels kind of wrong (dont't want to had any sort of dependencies on my domain objects, even if I abstract the GoogleMaps interface)</p>
  
  <p>Putting the reverse geocoding logic in the MVC controller feels wrong as well. No need to explain.</p>
  
  <p>I guess I should put the logic in the service Layer then but I'm confused on how to do it properly as I'm only deeling with a Meeting object (not an "Address").</p>
  
  <p>Thanks!</p>