I am currently working on a Web API project using the Database-First method using the Entity Framework (which, as I know, is not the most stable of the platforms yet), but I am encountering something very strange.
When the GET method in my APIController tries to return all records to the DbSet using the LINQ Include () method, which will be invoked in this way, it will return a 500 error:
// GET api/Casinos public IEnumerable<casino> Getcasinos() { var casinos = db.casinos.Include(c => c.city).Include(c => c.state); return casinos.AsEnumerable(); }
However, this method works fine and returns my data from my database:
// GET api/States public IEnumerable<state> Getstates() { return db.states.AsEnumerable(); }
So, in other cases, I proved that if it returns objects without LINQ queries, it works fine, but when there is an Include method used for DbContext, it fails.
Of course, trying to find this error is impossible even with the Fiddler, Chrome / Firefox dev tools and adding to GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
If someone allowed this, it would be nice to know a good resolution so that I can start returning my data! Thanks!)
PS I am using SQL Server 2012
source share