When utilizing Entity Framework with Oracle, an operation is not acceptable owing to the present state of the object.

c# entity-framework exception oracle oracle11g

Question

I'm trying to create a new entity object for persistence, but I'm receiving an error that says: UpdateException, inner exception InvalidOperationException

Operation is not valid due to the current state of the object.

Creating an object:

var something = new SITE
{
    EntityKey = new EntityKey("DataModelContainer.SITE", "SITE_ID", "ID"),
                    SITE_COMMON_REFERENCE = "hello",
                    SITE_ID = "hello"     
};

which is afterwards given to:

public void ExportSiteData (SITE exportSiteData)
{
    _context.SITE.AddObject(exportSiteData);
    _context.SaveChanges(); //<-- Exception here
}

Oracle 11g is the database, and Entity Framework allows me to successfully extract data from it.

Although I can successfully fill it with both "hello" values without experiencing any key or referential integrity issues, I'm speculating that the issue is more database-related.

Please send me in the appropriate path; I'd really appreciate it. Thanks

Added code

Contains ExportSiteDataBillRepository how are implementedIDisposable :

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 referred to as such

using (var repo = new BillRepository())
{
    repo.ExportSiteData(something);
}
1
2
1/4/2012 4:11:23 PM

Accepted Answer

Check that the primary key for the relevant table has StoreGeneratedPattern="Identity" in both parts by opening the.edmx file in xml. A recognized mistake occurs when the designer via EF edits one piece but leaves the other section alone. Find the following in both sections:

<EntityType Name="TIMELINE">
          <Key>
            <PropertyRef Name="ID"/>
          </Key>

  <Property Name="ID" Type="decimal" Nullable="false" Precision="19" StoreGeneratedPattern="Identity" />

See

2
5/23/2017 12:30:03 PM

Popular Answer

When attempting to update a previous project, I keep running across this issue.

Make that the version of the.NET framework stated in your package file matches the version of your project. If you have more than one project in your solution, make sure they are all set to the appropriate.net framework version, for instance, if net452 is specified, make sure your project is configured to use net 4.5.2.

I also observed that the project would get confused about which model file to upload when a new data model was added. I think my development box's TFS installation was the cause of this (I had express, then install latest). I temporarily detached the project from TFS in order to address this problem).



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow