Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomapper failing on double? property
    primarykey
    data
    text
    <p>I'm using AutoMapper to map Domain objects to ViewModel objects in my controller. Everything was working fine until I <strong>tried adding double?</strong> properties. I've started getting the following error:</p> <pre><code>Missing type map configuration or unsupported mapping. Mapping types: Address -&gt; AddressModel Domain.Address -&gt; Web.Models.AddressModel Destination path: AccountAddressModel.Address.Address Source value: Domain.Address </code></pre> <p>My Address class and AddressModel class both have two properties called Longitude and Latitude. These properties (in both classes) are defined as double?. If I comment out these properties, everything works fine. If I make all of these properties simply double, then everything works fine. It's only double? that causes the problem.</p> <p>I'm using <strong>AutoMapper 2.2.1</strong> downloaded via NuGet.</p> <p>I've read in other posts that this problem with nullables was supposed to be fixed. This leads me to believe I might be doing something different so I'm going to post my code to see if anyone can see something that might be an issue:</p> <p><strong>DOMAIN MODELS</strong></p> <pre><code>public class AccountAddress { public int Id { get; set; } public int AccountId { get; set; } public int AddressId { get; set; } public Address Address { get; set; } ... } public class Address : IUserTrackingEntity { public int Id { get; set; } public string Addressee { get; set; } public string Street1 { get; set; } public string Street2 { get; set; } ... public double? Longitude { get; set; } public double? Latitutde { get; set; } } </code></pre> <p><strong>VIEW MODELS</strong></p> <pre><code>public class AccountAddressEditModel { public string AccountName { get; set; } public AccountAddressModel Address { get; set; } public IList&lt;Country&gt; CountriesList { get; set; } ... } public class AccountAddressModel { public AccountAddressModel() { Address = new AddressModel(); } public int AccountId { get; set; } public int AddressId { get; set; } public int Id { get; set; } public AddressModel Address { get; set; } } public class AddressModel { public int Id { get; set; } public string Addressee { get; set; } [Required(ErrorMessage="A street address is required.")] public string Street1 { get; set; } public string Street2 { get; set; } ... public double? Longitude { get; set; } public double? Latitude { get; set; } } </code></pre> <p><strong>MAPPING CODE IN MY CONTROLLER</strong></p> <pre><code>//Get an AccountAddress address = _context.AccountAddresses.SingleOrDefault(ad =&gt; ad.Id == 12345); model = new AccountAddressEditModel(); Mapper.CreateMap&lt;AccountAddress, AccountAddressModel&gt;(); Mapper.CreateMap&lt;AccountAddress, AddressModel&gt;(); Mapper.Map(address, model.AccountAddress); </code></pre> <p>Has anyone else experienced this or found a solution for this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload