When I was trying to run the application I had faced this problem. I resolved by selecting the complete object that result will consists of complete customer objects. But before I selected a subset of the customer objects, just two members.
Problem:
var customerOrders = from customer in db.Customers
where customer.ContactName.StartsWith("C")
orderby customer.ContactName
select new {customer.ContactName, customer.Phone };
I got the following error,
The model item passed into the dictionary is of type'System.Data.Entity.Infrastructure.DbQuery`1[<>
f__AnonymousType2`2[System.String,System.String]]',but this dictionary requires a model item of type
'System.Collections.Generic.IEnumerable`1[LinQTutoris.Models.Customer]'.
Description: Anunhandled exception occurred during the execution of the current web request.Please review the stack trace for more information about the error and where itoriginated in the code.
Exception Details: System.InvalidOperationException:The model item passed into the dictionary is of type'System.Data.Entity.Infrastructure.DbQuery`1[<>f__AnonymousType2`2[System.String,System.String]]',but this dictionary requires a model item of type'System.Collections.Generic.IEnumerable`1[LinQTutoris.Models.Customer]'.
Solution:
edited the code,selecting the complete object of customer
var customerOrders = from customer in db.Customers
where customer.ContactName.StartsWith("C") orderby customer.ContactName
select customer;
Post your comments / questions
Recent Article
- How to add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
- How to enable Search Feature in Django admin?
Related Article