Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.
i write below code in controller:

public ActionResult Index()
{
var listOfPersonal =
(from Personals in db.Personals
select new Person
{
FirstName = Personals.FirstName,
LastName = Personals.LastName,
Phone = Personals.Phone
}).ToList();

return View(listOfPersonal);
}

----------------------------------------

but when run, below error :

An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: The entity or complex type 'ContosoUniversity.DAL.Personal' cannot be constructed in a LINQ to

what should i do?
thanks

What I have tried:

i dont know what should i do.
stuy very but no get any thing


help pleas
Posted
Updated 24-Jan-20 0:45am

Always google any error messages you get, there are lots of pages that explain the problem and solution, this is just one

The entity or complex type 'Categories' cannot be constructed in a LINQ to Entities query.[^]

You can search for more yourself

The entity or complex type cannot be constructed in a LINQ - Google Search[^]
 
Share this answer
 
As the message says, what you're doing is not supported in LINQ to SQL.
Specifically, creating a new object Person.
There is a simple workaround though. Just convert the data to .ToList() or .ToArray() and after that you can do Select:
.ToArray().Select(i => new Person { ... });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900