I've read this answer The entity cannot be constructed in a LINQ to Entities query but still, feel confused.
var ProductAndBuildInfoList= (
from p in db.Product
join pbc in db.product_builds_children on p.BuildId equals pbc.BUILD_ID
select new ProductAndBuildInfo {
Id = p.Id,
Name = p.name,
BuildRequestId = pbc.BUILD_REQ_ID
}
).ToList();
When I executed the above query, it threw out the exception
"The entity cannot be constructed in a LINQ to Entities query"
Here is the class for both ProductAndBuildInfo
and Product
public class ProductAndBuildInfo : Product {
public long BuildRequestId { get; set; }
}
public class Product {
public long Id { get; set; }
public string Name { get; set; }
}
I understand that we can't construct an object if it's a mapped entity, then what's the correct way to construct a new object inherited from a mapped entity? Copy all fields from the upper class to the lower class seems an unclean way to me.