影片講解
單一資料表操作
var result = _todoContext.TodoLists.FromSqlRaw("select * from todolist");
[HttpGet("GetSQL")]
public IEnumerable<TodoList> GetSQL(string name)
{
string sql = "select * from todolist where 1=1";
if (!string.IsNullOrWhiteSpace(name))
{
sql = sql + "and name like N'%" + name + "%'";
}
var result = _todoContext.TodoLists.FromSqlRaw(sql);
return result;
}