我已經創建低於AutoMapper映射配置類代碼的模型接口:使用AutoMapper到一個視圖模型映射到
public static class MilitaryBrochureViewModelMapper
{
public static void Configure()
{
ConfigureMilitaryBrochureMapping();
}
private static void ConfigureMilitaryBrochureMapping()
{
Mapper.CreateMap<IBrochureModel, MilitaryBrochureViewModel>().ForMember(dest => dest.Rank, opt => opt.MapFrom(src => src.JobTitle));
}
}
我映射在MilitaryBrochureViewModel領域排名到可變JOBTITLE在IBrochureModel接口時,我導航到MilitaryBrochureViewModel它告訴我,我還沒有完全實現接口,我需要放置任何視圖模型或接口或兩者都告訴他們我已經使用AutoMapper創建這兩個變量之間的映射?
下面是視圖模型和接口,我使用:
視圖模型
public class MilitaryBrochureViewModel : IBrochureModel
{
[Key]
public int Id { get; set; }
public virtual int TestMode { get; set; }
[DataType(DataType.Text)]
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[Display(Name = "Salutation", Description = "Salutation_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
public string Salutation { get; set; }
[DataType(DataType.Text)]
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[Display(Name = "First_Name", Description = "First_Name_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
[RegularExpression(@"^([\u00c0-\u024f]|[A-z]|[']|[ ]|[\-]){2,20}$", ErrorMessageResourceName = "FirstNameRegExError", ErrorMessageResourceType = typeof(Mui))]
public string FirstName { get; set; }
[DataType(DataType.Text)]
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[Display(Name = "Last_Name", Description = "Last_Name_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
[RegularExpression(@"^([\u00c0-\u024f]|[A-z]|[']|[ ]|[\-]){2,20}$", ErrorMessageResourceName = "LastNameRegExError", ErrorMessageResourceType = typeof(Mui))]
public string LastName { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email", Description = "Email_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
[RegularExpression(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessageResourceName = "EmailInputValidatorError", ErrorMessageResourceType = typeof(Mui))]
public virtual string Email { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[DataType(DataType.Text)]
[Display(Name = "Military_Rank", Description = "Military_Rank_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
[StrMinLen(5)]
[StrMaxLen(50)]
public string Rank { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[DataType(DataType.Text)]
[Display(Name = "Company", Description = "Company_Description", GroupName = "Personal", ResourceType = typeof(Mui))]
public string Company { get; set; }
[Required]
[Display(Name = "Do_Not_Pass_On", Description = "Do_Not_Pass_On_Description", GroupName = "Company", ResourceType = typeof(Mui))]
public bool DoNotPassOn { get; set; }
[DataType(DataType.Text)]
[Required(AllowEmptyStrings = false, ErrorMessageResourceName = "required", ErrorMessageResourceType = typeof(Mui))]
[Display(Name = "Lead_Source", GroupName = "Terms", Description = "Lead_Source_Description", ResourceType = typeof(Mui))]
public string LeadSource { get; set; }
}
接口
public interface IBrochureModel
{
int TestMode { get; set; }
string Salutation { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
string Email { get; set; }
string Company { get; set; }
string JobTitle { get; set; }
string LeadSource { get; set; }
bool DoNotPassOn { get; set; }
}
你可以發佈你的接口和viewmodel實現 – swapneel 2013-03-26 11:52:58