Hello All,
do anybody give me some examples on how to achieve update functionality using entity framework.
in my scenario i am taking data without primary key.
now i am having another column which is unique in this.
when i am passing these values to the database it's not getting updated.
below is my code which i am working on.
public void InsertBulkRecords(List<ShowHors> listshowhorse)
{
ShowHors updateShowHors = new ShowHors();
try
{
using (var context = new CurrentHorseShowEntities())
{
foreach (ShowHors item in listshowhorse)
{
var original = context.ShowHorses.Find(item.HorseId);
if (original.HorseId != null)
{
//Initially updateShowHors.ShowHorsesId is null. i am assigning it the
original.ShowHorsesId; value.
updateShowHors.ShowHorsesId = original.ShowHorsesId;
updateShowHors.ShowId = item.ShowId;
updateShowHors.HorseCatalog = item.HorseCatalog;
updateShowHors.IsActive = item.IsActive;
//context.SaveChanges();
context.Entry(original).CurrentValues.SetValues(updateShowHors);
context.SaveChanges();
}
}
}
}
catch
{
throw;
}
}
where am i getting wrong kindly let me know or kindly suggest me the best approach.