讀取一筆資料
寫法一
var result = _todoContext.Todos.Find(id);寫法二
var result = (from a in _todoContext.Todos where a.TodoId == id select a).SingleOrDefault();寫法三
var result = _todoContext.Todos.Where(p => p.TodoId == id).SingleOrDefault();指定讀取一筆api範例
// GET api/Todo/5 [HttpGet("{id}")] public Todo Get(Guid id) { //var result = _todoContext.Todos.Find(id); //var result = (from a in _todoContext.Todos // where a.TodoId == id // select a).SingleOrDefault(); var result = _todoContext.Todos.Where(p => p.TodoId == id).SingleOrDefault(); return result; }
感謝,講的很精細
回覆刪除