devtunis devtunis - 24 days ago 17
C# Question

Update with Entity Framework C#

I want to update items by Entity Framework,

The code is correct but i don't have result in my database!!

using(checkinentrepriseEntities2 context = new checkinentrepriseEntities2()) {
clients clien = new clients();

clien.date_arrival = DateTime.Parse(textBoxDateIN.Text);
clien.arrival_time = textBoxTIME.Text;
clien.Aller_A = comboboxPersonnel.SelectedItem.ToString();
clien.Badge = int.Parse(comboBoxBadge.SelectedItem.ToString());

int badgeTiped = int.Parse(comboBoxBadge.SelectedItem.ToString());

context.SaveChanges();
}

Answer

This code is creating a new clients object.

If you want to update results from the database you have to select the clients object from the database :

clients clien = context.clients.Single(x => x.Id == yourId);
// your logic
context.SaveChanges();
Comments