Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoMapper with Domain model
    primarykey
    data
    text
    <p>I am new for AutoMapper</p> <p>I have following domain Model.</p> <pre class="lang-cs prettyprint-override"><code>public class Contact { public string University { get; set; } public string GraduationYear { get; set; } } </code></pre> <p>I don't want to change domain model and would like to add extra attribute for GraduationYear property.</p> <p>I have created attribute class on my mvc 4 project</p> <pre class="lang-cs prettyprint-override"><code>[System.AttributeUsage(System.AttributeTargets.Property)] public class Mapping : System.Attribute { public string Name { get; set; } } </code></pre> <p>Used above attribute on class named 'ContactMapping' Created </p> <pre class="lang-cs prettyprint-override"><code>public class ContactMapping { [Telephony.Helper.Attribute.Mapping(Name = "Graduate")] public string GraduationYear { get; set; } } </code></pre> <p>I am getting contact object from domain service which doesn't have custom attribute 'Mapping'.</p> <pre class="lang-cs prettyprint-override"><code>var contact = new ContactService().Get(contactPredicate).Single(); </code></pre> <p>Now i am doing Auto Mapper</p> <pre class="lang-cs prettyprint-override"><code>AutoMapper.Mapper.CreateMap&lt;Telephony.Helper.Mapping.ContactMapping, Aurora.CustomersMvc.Domain.Contact&gt;(); var test = AutoMapper.Mapper.Map&lt;Aurora.CustomersMvc.Domain.Contact&gt;(contact); var contactwithCustomAttr = contact.GetType().GetProperties().Where(p =&gt; ((Telephony.Helper.Attribute.Mapping[])p.GetCustomAttributes(typeof(Telephony.Helper.Attribute.Mapping), false)) .Any(attr =&gt; attr.ToString() == "Graduate")); </code></pre> <p>I am getting contactwithCustomAttr.Count() zero. I am expecting to return GraduationYear property as mapper should apply my custom property.</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.
    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