简体   繁体   English

实体框架对象不持久/保存到数据库表

[英]Entity Framework object not persisting/saving to database table

I have entity model created in Visual Studio 2010.This is part of my code: 我在Visual Studio 2010中创建了实体模型。这是我的代码的一部分:

Database1Entities1 de = new Database1Entities1();
UserInfo ui = new UserInfo();
ui.Name = "xxx";
ui.Username = "xxx";
ui.Password = "xxx";
de.UserInfoes.AddObject(ui);

It executes without problems, but new data is no added in the table. 它执行没有问题,但表中没有添加新数据。 Does anybody know what the problem is? 有谁知道问题是什么?

You would need to call 你需要打电话

de.SaveChanges(); 

if this is Entity Framework to persist the changes back to the database. 如果这是实体框架,则将更改保留回数据库。

添加对象后,需要在de上调用save方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM