user979331 user979331 - 27 days ago 14
ASP.NET (C#) Question

Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbSqlQuery’ to 'System.Linq.IQueryable’

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?

Answer

Try using AsQuearable(). But as I noted in my comment, that can have repercussions.