title: ASP.NET MVC View classes and null
body: <p>I have a complex structure with nested view model classes:</p>
  
  <pre><code>public class ApplicationDriverFormVM : IValidatableObject
  {
      [Required]
      public string Sign { get; set; }
  
      public string Company { get; set; }
  
      public ApplicationDriverAddressFormVM PresentAddress { get; set; }
      public List&lt;ApplicationDriverAddressFormVM&gt; PreviousAddresses { get; set; }
  
      public ApplicationDriverLicenseFormVM License { get; set; }
  
      public ApplicationDriverEducationFormVM Education { get; set; }
  
      public List&lt;ApplicationDriverAdditionalLicenseFormVM&gt; AdditionalLicenses { get; set; }
  
  
      //public ApplicationDriverAccidentFormVM DefaultAccident { get; set; }
      public List&lt;ApplicationDriverAccidentFormVM&gt; Accidents { get; set; }
  
      public List&lt;ApplicationDriverTrafficConvictionFormVM&gt; TrafficConvictions { get; set; }
  
      public List&lt;ApplicationDriverEmployerFormVM&gt; Employers { get; set; }
  
  
      public ApplicationDriverEquipmentTractorFormVM EquipmentTractor { get; set; }
      public ApplicationDriverEquipmentTrailerFormVM EquipmentTrailer { get; set; }
      public ApplicationDriverEquipmentStraightTruckFormVM EquipmentStraightTruck { get; set; }
      public ApplicationDriverEquipmentCargoVanFormVM EquipmentCargoVan { get; set; }
  
      public ApplicationDriverFormVM()
      {
          PresentAddress = new ApplicationDriverAddressFormVM();
          PreviousAddresses = new List&lt;ApplicationDriverAddressFormVM&gt;();
          PreviousAddresses.Add(new ApplicationDriverAddressFormVM());
          License = new ApplicationDriverLicenseFormVM();
          Education = new ApplicationDriverEducationFormVM();
          AdditionalLicenses = new List&lt;ApplicationDriverAdditionalLicenseFormVM&gt;();
          AdditionalLicenses.Add(new ApplicationDriverAdditionalLicenseFormVM());
          Accidents = new List&lt;ApplicationDriverAccidentFormVM&gt;();
          Accidents.Add(new ApplicationDriverAccidentFormVM());
          TrafficConvictions = new List&lt;ApplicationDriverTrafficConvictionFormVM&gt;();
          TrafficConvictions.Add(new ApplicationDriverTrafficConvictionFormVM());
          Employers = new List&lt;ApplicationDriverEmployerFormVM&gt;();
          Employers.Add(new ApplicationDriverEmployerFormVM());
          EquipmentTractor = new ApplicationDriverEquipmentTractorFormVM();
          EquipmentTrailer = new ApplicationDriverEquipmentTrailerFormVM();
          EquipmentStraightTruck = new ApplicationDriverEquipmentStraightTruckFormVM();
          EquipmentCargoVan = new ApplicationDriverEquipmentCargoVanFormVM();
      }
  }
  </code></pre>
  
  <p>And each of them nested classes can have nested classes too...</p>
  
  <p>Problem is many of these classes do not have any required field, so, client can leave all fields of some class as empty. In result, controller gets object like this:</p>
  
  <p><a href="https://i.stack.imgur.com/VksjV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VksjV.jpg" alt="enter image description here"></a></p>
  
  <p>AutoMapper maps this class to domain (and then infrastructure) class and each entity saves in DB as different record in appropriate table. But I don't want to save empty records, I want to not map them to domain classes. How to do it? Validate each object for null of all its property or there is more strong solution?</p>