سوال: چگونه استفاده از ارتباط جداول وقتی که از viewmodel و autommaper استفاده می کنید؟

ساخت وبلاگ

سلام.
به عنوان مثال من 2 تا جدول زیر رو دارم


public class Product
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
[MaxLength(10)]
public string Price { get; set; }
//relation
public Guid? PImageId { get; set; }
[ForeignKey("PImageId")]
public virtual PImage PImage { get; set; }
}

و

[Key]
public Guid Id { get; set; }
[MaxLength(200)]
public string Name { get; set; }
public string ImgUrl { get; set; }
public DateTime? IDateTime { get; set; }
public ICollection<Product> Products { get; set; }

و ویو مدل بصورت زیر


public class ProductAVm
{
public int Id { get; set; }
public string Name { get; set; }
[MaxLength(10)]
public string Price { get; set; }
[MaxLength(10)]
public Guid? PImageId { get; set; }
public virtual PImageAVm PImage { get; set; }
}

خوب بصورت زیر هم اینها رو با هم مپ می کنیم

public IEnumerable<ProductAVm> Gets()
{
var model = _repository.Gets();
Mapper.CreateMap<Product, ProductAVm>();
retu Mapper.Map<IEnumerable<Product>, IEnumerable<ProductAVm>>(model);
}

اما موقع استفاده از اون به ارور زیر برخورد می کنم! حتما باید از مدل استفاده کنم و نمی شه ویو مدل رو استفاده کرد؟

erormap.png

http://s6.picofile.com/file/8236438626/erormap.png

- - , .

برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : محمد رضا جوادیان programers بازدید : 94 تاريخ : دوشنبه 12 بهمن 1394 ساعت: 15:44