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

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

Article:
Viewed:  1309 
Posted On:  4/16/2015 7:37:43 PM 
The entity cannot be constructed in a LINQ to Entities query 

 

While Fetching data from tables if you face below error…

1.png
 

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
                            }).ToList()
                      .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());
        }
 

2.png

Image 2.

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