Код: Выделить всё
public partial class Material
{
public System.Guid Id { get; set; }
public string Description { get; set; }
public string EAN { get; set; }
public virtual InventoryLine InventoryLine { get; set; }
}
public partial class InventoryLine
{
public System.Guid MaterialId { get; set; }
public Nullable Quantity { get; set; }
public decimal Price { get; set; }
public Nullable LastInspectionDate { get; set; }
public int TransactionsSinceLastInspection { get; set; }
public virtual Material Material { get; set; }
}
public class InventoryLineViewModel
{
public string EAN { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public decimal? Quantity { get; set; }
public DateTime? LastInspectionDate { get; set; }
}
< /code>
У меня есть это отображение: < /p>
CreateMap().ForMember(d => d.Price, o => o.MapFrom(s => s.InventoryLine.Price)).ForMember(d => d.Quantity, o => o.MapFrom(s => s.InventoryLine.Quantity)).ForMember(d => d.LastInspectionDate, o => o.MapFrom(s => s.InventoryLine.LastInspectionDate));
< /code>
всякий раз, когда я запускаю этот код: < /p>
Mapper.Initialize(c => { c.AddProfile(new MapperProfile()); });
return context.Material.Include(i => i.InventoryLine).ProjectTo().ToList();
< /code>
Я получаю эту ошибку: < /p>
Cast to Value Type 'System.decimal' не удалось, поскольку материализованное значение равна нулю. Либо общий параметр типа результата, либо запрос должен использовать нулевой тип. Я даже пытался сделать свойство Любая справка оценена:-) < /p>
Подробнее здесь: https://stackoverflow.com/questions/411 ... ue-is-null