The entity or complex type cannot be constructed in a LINQ to Entities query

You cannot (and should not be able to) project onto a mapped entity. You can, however, project onto an annonymous type or onto a DTO:

public class ProductDTO
{
    public string Name { get; set; }
    // Other field you may need from the Product entity
}

And your method will return a List of DTO’s.

public List<ProductDTO> GetProducts(int categoryID)
{
    return (from p in db.Products
            where p.CategoryID == categoryID
            select new ProductDTO { Name = p.Name }).ToList();
}

 

Source: https://stackoverflow.com/questions/5325797/the-entity-cannot-be-constructed-in-a-linq-to-entities-query

Another Solution

http://www.c-sharpcorner.com/blogs/error-the-entity-or-complex-type-cannot-be-constructed-in-a-linq-to-entities-query1

 

Advertisements

Auditing Data Changes in the Entity Framework

https://blogs.msdn.microsoft.com/simonince/2009/04/17/auditing-data-changes-in-the-entity-framework-part-1/

https://blogs.msdn.microsoft.com/simonince/2009/04/20/auditing-data-changes-in-the-entity-framework-part-2/

https://www.codeproject.com/Articles/1019511/Audit-trail-and-data-versioning-with-Csharp-and-MV

http://benjii.me/2014/03/track-created-and-modified-fields-automatically-with-entity-framework-code-first/

http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2011/07/26/auditing-with-entity-framework.aspx

http://www.jigar.net/articles/viewhtmlcontent344.aspx

https://www.exceptionnotfound.net/entity-change-tracking-using-dbcontext-in-entity-framework-6/