[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
Run Code Online (Sandbox Code Playgroud)
此操作接收电影模型并在数据库中更新它.
但我无法弄清楚如何.
该movie对象未附加到db,那么实体框架如何知道db中哪一行应该更新?
我确信Entry方法与它有关,但我真的不知道这个方法的作用.我读到它提供了信息,但是我无法理解如何只更改State一个条目,它将被附加和跟踪DBContext.
我正在尝试使我的控制台原始(在 Windows 上),并且我正在使用 ssh/终端包:
package main
import (
"fmt"
"os"
"golang.org/x/crypto/ssh/terminal"
)
type sh struct{}
func (sh *sh) Read(b []byte) (int, error) {
return os.Stdin.Read(b)
}
func (sh *sh) Write(b []byte) (int, error) {
return os.Stdout.Write(b)
}
func main() {
oldstate, err := terminal.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer terminal.Restore(int(os.Stdin.Fd()), oldstate)
term := terminal.NewTerminal(&sh{}, "")
term.AutoCompleteCallback = func(line string, pos int, key rune) (newLine string, newPos int, ok bool) {
fmt.Println("callback:", line, pos, key)
return "", 0, …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
#include <iostream>
using namespace std;
template <class T>
class Iterator;
template <class T>
class List;
template <class T>
class List {
public:
struct Node;
Node* first;
friend class Iterator<T>;
List() :
first(NULL) { }
Iterator<T> begin() {
cout << first->data << endl;
return Iterator<T>(*this, first); // <--- problematic call
}
void insert(const T& data) {
Node newNode(data, NULL);
first = &newNode;
}
};
template <class T>
struct List<T>::Node {
private:
T data;
Node* next;
friend class List<T>;
friend class …Run Code Online (Sandbox Code Playgroud)