C# - Entity Framework add new object to ObjectContext

c# devexpress entity-framework objectcontext xtragrid

Question

im working with Entity Framework, SQL and C#.

i have a Table called Client and other called clients_phone.

I have a form with a Xtragrid and using BindingSource I bind the IQueryable to the grid.

myBindingSource = new BindingSource();
myBindingSource.DataSource = clients;  //Clients it is the IQueryable<Client>
myBindingSource.DataMember = "clients_phone";
myBindingSource.AllowNew = true;

Then, i wan to add a new clients_phone to my client. To do this, i make a New Client() and then add the Phone.

clients newclient = objContext.CreateObject<clients>();

newclient.clients_phone = newClients_Phone;

objContext.AddObject("Clients", newclient);

Finally i add the new clients_phone in the ObjectContext, but when i see the Xtrag clients_phone don't show.

Any idea of what happens??.

Thanks

Popular Answer

Lucas B is right. Whenever you've gotten round to adding all the new Clients and Clients_phone's you need to call the SaveChanges() method in order to persist the data into the database.

Whether you need to create the client first and then do an update to add further client_phone entries or whatever. If you never call SaveChanges() method nothing you do will be saved back to the database.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow