I am trying to follow this tutorial:
but can't seem to to access this method, it will not show up in intelli-sense
context.Database.SqlQuery
I am using the following code but can't seem to access the SqlQuery method:
using(Entities db = new Entities())
{
}
The method you have described is valid for executing SQL vs a DbContext
version of EF. (DbContext
is used for Code First and is also available for model first but you need to do a little setup). However in your example it should be the following.
using(Entities db = new Entities())
{
db.Database.SqlQuery(....);
}
If you are using OOB model first (ie edmx), you are probably using an ObjectContext
, in which case you will need to perform the following:
using(Entities db = new Entities())
{
db.ExecuteStoreQuery<ReturnType>("...");
}