I tried something from a little googling which fixed my problem, i'm not sure if this is the ideal or recommended approach but it worked.
I added this to the Automapper projects 'AssemblyInfo.cs' file:
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
I recompiled and used the new DLL and everything worked fine.
Please leave comments if this isn't reccomended or if there is a better approach.
For now though i will leave my own answer as the correct one.
Thanks for the help though!
UPDATE:
My mappings are pretty simple, sorry about all the code but thought it may help you:
Initialisation Code:
Mapper.Reset();
Mapper.Initialize(x =>
{
x.AddProfile<LeadsProfile>();
//x.AddProfile<AttendeeProfile>();
});
Mapper.AssertConfigurationIsValid();
LeadsProfile.cs
public class LeadsProfile : AutoMapper.Profile
{
public override string ProfileName
{
get { return "LeadsProfile"; }
}
protected override void Configure()
{
Mapper.CreateMap<Lead, LeadDto>();
Mapper.CreateMap<Lead, LeadDetailDto>();
Lead lead = null;
Mapper.CreateMap<int, LeadDetailDto>()
.BeforeMap((s, d) => lead = ServiceLocator.Current.GetInstance<ILeadRepository>().FindOne(s))
.ForMember(d => d.Id, x => x.MapFrom(s => lead.Id))
.ForMember(d => d.Fullname, x => x.MapFrom(s => lead.Fullname))
.ForMember(d => d.TelNumber, x => x.MapFrom(s => lead.TelNumber))
.ForMember(d => d.BookedAppointmentDate, x => x.MapFrom(s => lead.BookedAppointmentDate));
}
}
Source Class
public class Lead : Entity
{
public Lead()
{
Status = Common.LeadStatus.Raw;
CreatedDate = DateTime.Now;
}
public Lead(Branch branch, Promoter promoter, LeadSource source, string fullname, string telNumber, Address address, DateTime apptDate) : this()
{
this.Branch = branch;
this.Promoter = promoter;
this.Source = source;
this.Fullname = fullname;
this.TelNumber = telNumber;
this.Address = address;
this.BookedAppointmentDate = apptDate;
}
public virtual Branch Branch { get; set; }
public virtual Promoter Promoter { get; set; }
public virtual LeadSource Source { get; set; }
public virtual Common.LeadStatus Status { get; set; }
public virtual bool ExistingCustomer { get; set; }
public virtual bool IsDoso { get; set; }
public virtual string TitlePrefix { get; set; }
public virtual string Fullname { get; set; }
public virtual string TelNumber { get; set; }
public virtual string MobileNumber { get; set; }
public virtual DateTime BookedAppointmentDate { get; set; }
public virtual Address Address { get; set; }
public virtual Store Store { get; set; }
public virtual IList<LeadProduct> Products { get; set; }
public virtual IList<Appointment> Appointments { get; set; }
public virtual IList<Sale> Sales { get; set; }
public virtual DateTime CreatedDate { get; set; }
}
Destination Dto's
public class LeadDto
{
public int Id { get; set; }
public string Fullname { get; set; }
public string TelNumber { get; set; }
public DateTime BookedAppointmentDate { get; set; }
}
public class LeadDetailDto
{
public int Id { get; set; }
public string Fullname { get; set; }
public string TelNumber { get; set; }
public DateTime BookedAppointmentDate { get; set; }
}