I try to bring a data collection using LINQ to SQL but when I run the app it gives me an error, I'm using Visual Studio 2012 SQL Server 2008, Windows Forms app.
private IEnumerable<Customers> ListarCustomers()
{
using (NorthwindDataContext db = new NorthwindDataContext())
{
IEnumerable<Customers> custs = db.Customers.Where(x => x.City == "Rio de Janeiro")
.Select(x => new Customers() {CustomerID = x.CustomerID, ContactName = x.ContactName, City = x.City});
return custs.ToList();
}
}
The error is as follows: The explicit construction of the entity type 'DemoDGV.Customers' in a query is not allowed. DemoDGV is the name of the project.
I also get the following error The discarded object can not be accessed. \ R \ nName of the object: 'Access to DataContext was obtained after Dispose.' ""}