Firstly i am using EF v6.0. I have this function below;
public List<UserProgressViewModel> GetUserProgresses(int userId)
{
return Context.Database.SqlQuery<UserProgressViewModel>(
"SELECT Puzzles.Name AS PuzzleName, UserProgresses.Minute, " +
"UserProgresses.Session FROM UserProgresses " +
"INNER JOIN Puzzles ON Puzzles.Id = UserProgresses.PuzzleId " +
"WHERE UserProgresses.UserId = @userid", new SqlParameter("@userid", userId)).ToList();
}
And my UserProgressViewModel class is below;
public class UserProgressViewModel
{
public string PuzzleName { get; set; }
public int Minute { get; set; }
public int Session { get; set; }
}
(This class isn't a DbSet, it's only a view model.)
When i run the application (it's a WebAPI project) i get this error:
"Incorrect syntax near 'UserProgresses'."
I tried running this query on Mssql and it works fine. Results came just as i exptected.
I searched if EF 6.0 doesn't support raw sql query like this one, but it does support.
(According to this page: http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application#rawsql )
What is this thing that i can't see?
Thank you, have a great one!