I created an Entity Framework API Controller and now I am trying to adjust my GetData() method from:
public IQueryable<VIPPreviewTimeSlots> GetData()
{
return db.Data;
}
to
public IQueryable<VIPPreviewTimeSlots> GetData()
{
return db.Data.SqlQuery("SELECT a,b,c FROM table INNER JOIN another table....");
}
but I get this error:
Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbSqlQuery’ to 'System.Linq.IQueryable’
How do I cast this to a IQueryable?
.AsQueryableon a.SqlQuery. Changing the function signature to an IEnumerable will cause it to no longer be able to be lazily chainable. Everything afterward will then be done client-side instead of server-side..AsQueryableis the correct answer here (and it actually would be the correct answer on your linked question as well, but it has possible performance implications on.SqlQuerywhere here it does not.