Retrieve table data from stored procedure using entity framework

var result = db.GetCountryListSP();//Send parameters too

var countryList = dbContext.Database.SqlQuery<CountryName>(“[GetCountryList]”).ToList();







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



Another Solution


Auditing Data Changes in the Entity Framework