Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Error- The entity or complex type cannot be constructed in a linq to entities query

Viewed:  2658 
Posted On:  16/04/2015 19:37:43 
The entity cannot be constructed in a LINQ to Entities query 


While Fetching data from tables if you face below error…


Image 1.

To avoid this error replace your code with below code:

public ActionResult Index()
        var students = (from p in objContext.Students
                            join f in objContext.Courses
                        on p.CourseId equals f.CourseId
                            select new
                                Id = p.Id,
                                Name = p.Name,
                                DateOfBirth = p.DateOfBirth,
                                EmailId = p.EmailId,
                                Address = p.Address,
                                City = p.City,
                                CourseName = f.CourseName
                      .Select(x => new Student()
                          Id = x.Id,
                          Name = x.Name,
                          DateOfBirth = x.DateOfBirth,
                          EmailId = x.EmailId,
                          Address = x.Address,
                          City = x.City,
                          CourseName = x.CourseName
        return View(students.ToList());


Image 2.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us