Getting the below error while updating date fields of our Oracle table that has Composite Primary Key using Entity Framework. We checked all answers listed in the other thread (Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0).") like entity state, id fields missing, and etc, but none of those helped. So creating new question to get fresh answer for this issue. Please note that we are using DevArt to connect to Oracle database.
"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries"
Here is the code we are trying:
using (var context = new OracleContext(_connString))
{
var dbObjT = context.ReportHistoryDatas.FirstOrDefault(x => x.key1.Trim() == "300041" && x.key2== 1);
if(dbObjT != null)
{
dbObjT.DateUpdated = someDate;
context.SaveChanges();
}
}
Report History Data entity:
public class ReportHistoryData
{
//PK ID
public int key1 { get; set; }
public string key2{ get; set; }
public DateTime? DateAdded { get; set; }
public DateTime? DateUpdated { get; set; }
public class ReportHistoryDataConfiguration : EntityTypeConfiguration<ReportHistoryData>
{
public ReportHistoryDataConfiguration()
{
ToTable("REPORTHISTORY");
HasKey(k => new {k.key1, k.key2});
Property(p => p.key1).HasColumnName("key1").IsRequired();
Property(p => p.key2).HasColumnName("key2").IsRequired();
Property(p => p.DateAdded).HasColumnName("Date_Added");
Property(p => p.DateUpdated).HasColumnName("Date_Updated");
}
}
}