نکتهای در استفاده از AutoMapper
نویسنده: سیدمجتبی حسینی
تاریخ: ۱۳۹۱/۰۵/۲۱ ۲:۵۳
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Family { get; set; }
public DateTime Birthdate { get; set; }
public string Tel { get; set; }
public string CellPhone { get; set; }
[Email]
public string Email { get; set; }
}
public class StudentViewModel
{
public string Name { get; set; }
public string Family { get; set; }
public string Email { get; set; }
}
public ActionResult Index()
{
var model = db.Students.ToList();
AutoMapper.Mapper.CreateMap<Student,StudentViewModel>();
var studentViewModel = AutoMapper.Mapper.Map<List<Student>, IEnumerable<StudentViewModel>>(model);
return View(studentViewModel);
}
AutoMapper.Mapper.CreateMap<Student,StudentViewModel>();
An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code