I'm attempting to add a new Entity object for persistence, however I'm getting an UpdateException who's inner exception is an InvalidOperationException with the message:
Operation is not valid due to the current state of the object.
Object being created:
var something = new SITE
{
EntityKey = new EntityKey("DataModelContainer.SITE", "SITE_ID", "ID"),
SITE_COMMON_REFERENCE = "hello",
SITE_ID = "hello"
};
which is then passed to:
public void ExportSiteData (SITE exportSiteData)
{
_context.SITE.AddObject(exportSiteData);
_context.SaveChanges(); //<-- Exception here
}
The database is Oracle 11g and I can succesfully extract data via Entity Framework.
I'm guessing the problem is more database side, however I can successfully populate it with both "hello" values with no key/referential integrity problems.
I'd much appreciate being pointed in the right direction. Thanks
More code:
ExportSiteData is within BillRepository
which implements IDisposable
:
class BillRepository : IDisposable
{
private readonly DataModelContainer _context;
public BillRepository()
{
_context = new DataModelContainer();
}
public void ExportSiteData (SITE exportSiteData)
{
_context.SITE.AddObject(exportSiteData);
_context.SaveChanges(); //<-- Exception here
}
public void Dispose()
{
if (_context != null)
{
_context.Dispose();
}
}
}
and is called as such:
using (var repo = new BillRepository())
{
repo.ExportSiteData(something);
}