I generated my entities via the DbContext generator, and added it to an API controller that uses my entities context model. The following method fails to compile though:
public IEnumerable<casino> Getcasinos()
{
var casinos = db.casinos.Include(c => c.city).Include(c => c.state);
return casinos.AsEnumerable();
}
The compiler says:
Cannot Convert Lambda Expression to Type 'String' Because It Is Not A Delegate Type
Any ideas why it is saying this? I have the System.Linq namespace imported.
This actually happens because of the
ObjectQuery(T).Includemethod. This has the function signature:The reason why you’re seeing that is probably because wherever you’re calling it does not have the
System.Data.Entitynamespace available. From theDbExtensionsmetadata you can see that theIncludeusing an expression requires theSystem.Data.Entitynamespace:If you include the
System.Data.Entitynamespace, the error will resolve.