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 (9) -

  • 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>

  • college campuzhit

    11/11/2018 2:45:38 PM | Reply

    Someone necessarily assist to make significantly articles I'd state. This is the first time I frequented your web page and to this point? I amazed with the analysis you made to create this particular publish extraordinary. Fantastic activity!

  • Runspace

    5/29/2019 2:57:44 AM | Reply

    It is sure that there are so many quires in people's mind, hope this will clear it out https://run3space.com