title: How do I add a new text value from a WPF textbox to a database using the Entity Framework?
body: <p>I have a problem with adding text to the database, namely I have three tables:</p>
  
  <p><a href="https://i.stack.imgur.com/HvpUg.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>In WPF, the registration looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/1wEDA.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>In buttonSend I added such a code:</p>
  
  <pre><code>private void ButtonRegister_Click(object sender, RoutedEventArgs e)
  {
          model.Imie = Imie.Text.Trim();
          model.Nazwisko = Nazwisko.Text.Trim();
          model.Pesel = PESEL.Text.Trim();
          model.Adres.Ulica = Ulica.Text.Trim();
          model.Adres.Numer_domu = NumerD.Text.Trim();
          model.Adres.Numer_mieszkania = NumerM.Text.Trim();
          model.Kontakt.Telefon = Telefon.Text.Trim();
          model.Kontakt.email = Email.Text.Trim();
  
          using (eDoctorEntities db = new eDoctorEntities())
          {
              db.Pacjents.Add(model);
              db.SaveChanges();
          }
  
          MessageBox.Show("Zarejestrowano !");
  }
  </code></pre>
  
  <p>The program throws an error:</p>
  
  <blockquote>
    <p>System.NullReferenceException: 'The object reference has not been set to the instance of the object.'</p>
  </blockquote>
  
  <p>on the line</p>
  
  <pre><code>model.Adres.Ulica = Ulica.Text.Trim();
  </code></pre>
  
  <p>How to fix this? Please help me.</p>