我有一个使用实体框架设置的 .sdf 数据库。我的代码如下。但是,当我尝试更新第一条记录时,它使用 console.writeline() 正确显示了这一点,但是当我在 Visual Studio 中“显示表数据”时,我可以看到原始值仍然存在,它没有更新:
static void Main(string[] args)
{
Database2Entities context = new Database2Entities();
DbSet<Product> products = context.Products;
foreach (var product in products)
{
Console.WriteLine(product.name);
}
Console.WriteLine("---");
Product prod = products.First();
prod.name = "Faux lion fur hat";
context.SaveChanges();
products = context.Products;
foreach (var product in products)
{
Console.WriteLine(product.name);
}
Console.Read();
}
/*Output:
gloves
scarves
coates
lionFurHat
boots
---
Faux lion fur hat //This doesn't show in the diagram.
scarves
coates
lionFurHat
boots*/