Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7020455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:19:15+00:00 2026-05-27T23:19:15+00:00

I have the following entities: public class ContactDetailsJson { public string Zip { get;

  • 0

I have the following entities:

public class ContactDetailsJson
{
    public string Zip { get; set; }
    public string Phone { get; set; }
    public string AreaCode { get; set; }
    public DateTime UpdatedDate { get; set; }
    public string SeoContactUrl { get; set; }
    public string State { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public string CompanyName { get; set; }
    public string ContactUrl { get; set; }
    public string Country { get; set; }
    public bool Owned { get; set; }
    public string City { get; set; }
    public string Title { get; set; }
    public string Email { get; set; }
    public string Address { get; set; }
    public string CompanyId { get; set; }
    public string ContactId { get; set; }
}

public class ExternalContactSearchResultsViewModel
{
    public int DisplayedPageNumber { get; set; }
    public int TotalResultsCount { get; set; }
    public int PageSize { get; set; }
    public IList<ContactResultViewModel> Results { get; set; }

    public class ContactResultViewModel
    {
        public string ContactId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Headline { get; set; }
        public string Company { get; set; }
        public string PublicUrl { get; set; }
        public bool HasAccess { get; set; }
        public DateTime LastUpdatedDate { get; set; }
    }
}

To support the conversion, I have the following mappings created, which I have verified are being run:

        Mapper.CreateMap<ContactDetailsJson, ExternalContactSearchResultsViewModel.ContactResultViewModel>()
            .ForMember(dest => dest.Company, opt => opt.MapFrom(src => src.CompanyName))
            .ForMember(dest => dest.ContactId, opt => opt.MapFrom(src => src.ContactId))
            .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName))
            .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.LastName))
            .ForMember(dest => dest.HasAccess, opt => opt.MapFrom(src => src.Owned))
            .ForMember(dest => dest.Headline, opt => opt.MapFrom(src => src.Title))
            .ForMember(dest => dest.LastUpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
            .ForMember(dest => dest.PublicUrl, opt => opt.Ignore());

Unfortunately, this mapping results in all properties being null (or default values), as can be seen from the following unit test

    [TestMethod]
    public void Automapper_Contact_Details_Json_Can_Be_Mapped()
    {
        // Setup
        EntityMapLoader.LoadEntityMappings();
        DateTime testDate = DateTime.Now;

        var json = new ContactDetailsJson
        {
            CompanyName = "company",
            ContactId = "12345",
            FirstName = "first",
            LastName = "last",
            Owned = true,
            Title = "title",
            UpdatedDate = testDate
        };

        // Act
        var result = Mapper.Map<ContactDetailsJson, ExternalContactSearchResultsViewModel.ContactResultViewModel>(json);

        // Verify
        Assert.IsNotNull(result, "result was null");
        Assert.AreEqual("company", result.Company);
        Assert.AreEqual("12345", result.ContactId);
        Assert.AreEqual("first", result.FirstName);
        Assert.AreEqual("last", result.LastName);
        Assert.AreEqual(true, result.HasAccess);
        Assert.AreEqual("title", result.Headline);
        Assert.AreEqual(testDate, result.LastUpdatedDate);
    }

I can’t figure out what is wrong. Does anyone else see anything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:19:16+00:00Added an answer on May 27, 2026 at 11:19 pm

    I tried this and it works for me, I think its something wrong in way you are loading mapping or check if you are using latest version of automapper

     [TestFixture]
    public class UnitTest
    {
    
        [Test]
        public void Automapper_Contact_Details_Json_Can_Be_Mapped()
        {
            // Setup 
    
            DateTime testDate = DateTime.Now;
    
            var json = new ContactDetailsJson
            {
                CompanyName = "company",
                ContactId = "12345",
                FirstName = "first",
                LastName = "last",
                Owned = true,
                Title = "title",
                UpdatedDate = testDate
            };
            Mapper.CreateMap<ContactDetailsJson, ExternalContactSearchResultsViewModel.ContactResultViewModel>()
            .ForMember(dest => dest.Company, opt => opt.MapFrom(src => src.CompanyName))
            .ForMember(dest => dest.ContactId, opt => opt.MapFrom(src => src.ContactId))
            .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName))
            .ForMember(dest => dest.LastName, opt => opt.MapFrom(src => src.LastName))
            .ForMember(dest => dest.HasAccess, opt => opt.MapFrom(src => src.Owned))
            .ForMember(dest => dest.Headline, opt => opt.MapFrom(src => src.Title))
            .ForMember(dest => dest.LastUpdatedDate, opt => opt.MapFrom(src => src.UpdatedDate))
            .ForMember(dest => dest.PublicUrl, opt => opt.Ignore()); 
    
            // Act 
            var result = Mapper.Map<ContactDetailsJson, ExternalContactSearchResultsViewModel.ContactResultViewModel>(json);
    
            // Verify 
            Assert.IsNotNull(result, "result was null");
            Assert.AreEqual("company", result.Company);
            Assert.AreEqual("12345", result.ContactId);
            Assert.AreEqual("first", result.FirstName);
            Assert.AreEqual("last", result.LastName);
            Assert.AreEqual(true, result.HasAccess);
            Assert.AreEqual("title", result.Headline);
            Assert.AreEqual(testDate, result.LastUpdatedDate);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following entities: public class Product { [Key] public int Id{get;set;} //other properties
I have following two entities public class User { public int UserId { get;
I have the following @Entities @Entity public class Configuration{ @OneToMany protected Map<String, Component> components;
I have the following entities: public class User { public virtual ICollection<Role> Roles {
I have the following two entities: public class Entity1 { public IList e2 {
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
We have the following two entities with many-to-many association: @Entity public class Role {
I have following two entities public class User { [Key] public int Id {
I have the following entities public class Category { Id Name } public class
Suppose we have the following entities: public class plaserv { public virtual int id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.