Ich habe ein Problem über Liste zu Liste Problem.C# Converting List wirft Ausnahme in linq Abfrage
Meine Models:
public partial class OrderDetail
{
public int Id { get; set; }
public int OrderId { get; set; }
public string SparePartName { get; set; }
public Nullable<decimal> SparePartPrice { get; set; }
public Nullable<decimal> Labor { get; set; }
public Nullable<decimal> Total { get; set; }
public string Comment { get; set; }
}
public partial class Orders
{
public int Id { get; set; }
public int CustomerId { get; set; }
public int StorageId { get; set; }
public int UserId { get; set; }
public Nullable<System.DateTime> DateEntry { get; set; }
public Nullable<System.DateTime> DateRelease { get; set; }
public Nullable<System.DateTime> DateEstimatedRelease { get; set; }
public Nullable<System.DateTime> DateUpdate { get; set; }
public Nullable<decimal> Price { get; set; }
public int Status { get; set; }
public string FollowCode { get; set; }
public string DeviceBrand { get; set; }
public string DeviceModel { get; set; }
public string DeviceSerialNumber { get; set; }
public string DeviceComplaint { get; set; }
public string Comment { get; set; }
}
Meine Viewmodel:
public class VMOrderEdit
{
public int Id { get; set; }
public int StorageId { get; set; }
public int UserId { get; set; }
public string StorageName { get; set; }
public string CustomerName { get; set; }
public string CustomerTelephone { get; set; }
public DateTime? DateEntry { get; set; }
public DateTime? DateUpdate { get; set; }
public DateTime? DateRelease { get; set; }
public DateTime? DateEstimatedRelease { get; set; }
public decimal? Price { get; set; }
public string StatusName { get; set; }
public string FollowCode { get; set; }
public string DeviceBrand { get; set; }
public string DeviceModel { get; set; }
public string DeviceSerialNumber { get; set; }
public string DeviceComplaint { get; set; }
public string Comment { get; set; }
public int MyProperty { get; set; }
public List<VMOrderEditDetails> Details { get; set; }
}
public class VMOrderEditDetails
{
public int Id { get; set; }
public int OrderId { get; set; }
public string SparePartName { get; set; }
public decimal SparePartPrice { get; set; }
public decimal Labor { get; set; }
public decimal Total { get; set; }
public string Comment { get; set; }
}
Mein Controller:
List<VMOrderEdit> OrderEditObj = (from o in DB.Orders
join sn in DB.OrderStatusName on o.Status equals sn.Id
join st in DB.Storages on o.StorageId equals st.Id
join c in DB.Customers on o.CustomerId equals c.Id
where o.Id == Id
select new VMOrderEdit()
{
Id = o.Id,
StorageId = o.StorageId,
StorageName = st.Name,
UserId = o.UserId,
CustomerName = c.NameSurname,
CustomerTelephone = c.Telephone,
DateEntry = o.DateEntry,
DateUpdate = o.DateUpdate,
DateRelease = o.DateRelease,
Price = o.Price,
StatusName = sn.Name,
FollowCode = o.FollowCode,
DeviceBrand = o.DeviceBrand,
DeviceModel = o.DeviceModel,
DeviceSerialNumber = o.DeviceSerialNumber,
DeviceComplaint = o.DeviceComplaint,
Comment = o.Comment,
Details = DB.OrderDetail.Where(x => x.OrderId == o.Id).ToList()
}
).ToList();
auf dieser Linie:
Details = DB.OrderDetail.Where(x => x.OrderId == o.Id).ToList()
Visual Studio gibt diesen Fehler:
Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List
wie kann ich diesen Fehler umgehen?
'Details' ist eine' VMOrderEditDetails' Liste während 'DB.OrderDetail' ist (ich gehe davon) ein' OrderDetail' enumerable. – apokryfos
Die Frage ist, was 'OrderDetails' in 'Details' gespeichert werden soll, und dann eine geschachtelte Auswahl, um die 'Details' Eigenschaft zu füllen, dann ist ToList() –