The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

前端 未结 5 1543
太阳男子
太阳男子 2020-12-18 13:16

I been stuck in a situation and I tried finding the solution for it on net but was not successful. I am new to MVC with Entity Framework, and it is throwing the exception wh

5条回答
  •  时光取名叫无心
    2020-12-18 13:46

    None of the answers worked for me, but in the end, for some reason, EF 6 seemed to interpret this as a query:

    var patient = db.Patient.Where(p => p.ID == id);
    

    while this returned the Model I needed and works for me:

    var patient = db.Patient.Where(p => p.ID == id).FirstOrDefault();
    

提交回复
热议问题