eZeeNow.com

it's your's

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

In Linq-to-Entities you can only project to an anonymous type or a regular class. You can't project to an existing entity type. 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();
}

Comments (6) -

  • Roosevelt Barstad

    12/8/2017 6:32:18 PM | Reply

    Very nice post please let me share this information with you guys. In all honesty I was losing my house I didn’t know what I was going to do, until I came across this information about MONEY the government has for homeowners in rough times. They paid my mortgage here’s the info please share www.greenishmoney.com/need-help-paying-mortgage/ thank me later!

  • flip diving

    1/4/2018 7:18:47 PM | Reply

    Your site has a lot of useful information for myself. I visit regularly. Hope to have more quality items.
         <a href="http://flipdiving.online"; >flip diving</a>

Loading