Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to solve this error

$
0
0

"ExceptionMessage": "The entity or complex type 'WebApiStandAloneProject.Models.Student' cannot be constructed in a LINQ to Entities query.",

public IHttpActionResult GetAllStudent(bool includeAddress = false)      {                    var studentList = _context.Students.Include(c => c.Address).Select(m => new Student()          {              Id = m.Id,              FirstName = m.FirstName,              LastName = m.LastName,              Address = m.Address == null || includeAddress == false                     ? null                     : new Address()                     {                         StudentId = m.Id,                         Address1 = m.Address.Address1,                         Address2 = m.Address.Address2                     }          }).ToList<Student>();          if (!_context.Students.Any())          {              return NotFound();          }          return Ok(studentList);      }

Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>