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
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
Related Article