如何使用本机查询DBContext
?如果我运行代码,这会给我例外。为什么以及如何在使用时运行本机查询DBContext
?
AcademyEntities context = new AcademyEntities();
string nativeSQLQuery =
"SELECT * " +
"FROM dbo.Employees " +
"WHERE FirstName='{0}'";
string name = "Guy";
var emp = context.Departments.SqlQuery(nativeSQLQuery, name);
foreach (var item in emp)
{
}