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 get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
- urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0
Related Article