我确保完全理解以下代码:
static void Main(string[] args)
{
var person = new Person {FirstName = "Nadege",
LastName = "Deroussen", BirthDate = DateTime.Now};
using (var context = new MyContext())
{
context.Persons.Add(person);
context.SaveChanges();
}
Console.Write("Person saved !");
Console.ReadLine();
}
如您所见,使用 is 跟随 {},如果我错了,请纠正我,这是否意味着上下文将在 {} 之后关闭?DBContext 是否应该像这样每次都关闭?
祝大家欢呼