c# - Invalid operation exception in context.SaveChanges() with oracle entity framwork 5 -
i use oracle ef 5.0 provider. oracle 11g database. here database schema:
table has id primary key. each table in database there trigger, fires on insert new record , ef primary key after insert sequence. sequences created each table. in edmx file each id column has storegeneratedpattern="identity"
attribute set.
my code is:
using (var context = new entities()) { var title = new title { title_number = 4000001, is_draft = "n", registry_date = datetime.now }; var titlename = new title_name { name = "title name" }; title.title_name.add(titlename); context.set<title>().add(title); context.savechanges(); }
when context.savechanges()
executed, there exception thrown:
the changes database committed successfully, error occurred while updating object context. objectcontext might in inconsistent state. inner exception message: acceptchanges cannot continue because object's key values conflict object in objectstatemanager
. make sure key values unique before calling acceptchanges.
but changes saved in database correctly. , title object has correct id title , title_name
. can do? or wrong?
opps. remove inheritance edmx , error goes away!....
but project build in inheritance!!!
ops. ms sql same scheme gives exception too.
from here: https://entityframework.codeplex.com/workitem/2515
ef team triage: because have identity configured tpc mapping. because 2 types mapped separate tables, duplicate ids generated since database doesn't know generate unique values between 2 tables. 1 way around modify tables have 1 generate odd numbers , other generate numbers. workaround this.
we create interface shared properties entities , remove inheritance edmx file.
i.e.
public interface ihistoricalentity { int id { get; set; } int entity_id { get; set; } datetime create_date { get; set; } datetime delete_date { get; set; } int creator { get; set; } }
in partial file title.cs
public partial class title : ihistoricalentity { }
and can use generic version entities in our project.
Comments
Post a Comment