I made a test program for something totally unrelated to Entity Framework and what I thought would be an easy integration turned out to be troublesome. I have a DB Table called "TestEntry" which holds four data fields [ Id (uniqueidentifier), EId (uniqueidentifier), Name, Data ], these are unrelated to any other database tables and are standalone.
The issue is a simple update which is defined as such:
EDMEntities _db = new EDMEntities();
public List<TestEntry> GetEntities()
{
return _db.TestEntries.ToList();
}
public void EditEntry(TestEntry newEntry)
{
TestEntry entry = _db.TestEntries.FirstOrDefault(e => e.Id == newEntry.Id);
if (string.IsNullOrEmpty(newEntry.Name)) { entry.Name = newEntry.Name; }
if (string.IsNullOrEmpty(newEntry.Data)) { entry.Data = newEntry.Data; }
if (entry.EntityState == System.Data.EntityState.Modified)
{
_db.SaveChanges();
}
}
After stepping through it I noticed:
- Neither entry.Name nor entry.Data gets updated with the values from newEntry
- The EntityState remains unchanged thus not entering the conditional
Any ideas on what this could be?