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 Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article