Entity Framework object not persisting/saving to database table

106 Views Asked by At

I have entity model created in Visual Studio 2010.This is part of my code:

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?

2

There are 2 best solutions below

0
On

You would need to call

de.SaveChanges(); 

if this is Entity Framework to persist the changes back to the database.

0
On

You need to call the save method on de after you've added the object.