使用EF5插入时复制主键

时间:2018-03-28 08:31:52

标签: entity-framework

当我尝试使用此代码插入一些值时,我收到以下错误:

  

{" ORA-00001:违反了唯一约束(NCOREDB.PK_NCORE_CASH_IN)"}

我使用EF5和Oracle作为Database.It前一段时间工作正常。由于某些依赖性问题,我无法更新我的EF。

using (TransactionScope transactionScope = new TransactionScope())
        {
            try
            {

                NCORE_TRN_CASH_IN_INFO OBJ_NCORE_TRN_CASH_IN_INFO = new NCORE_TRN_CASH_IN_INFO();

                    int id = Convert.ToInt32(Obj_nCoreEntities.NCORE_TRN_CASH_IN_INFO.Max(t => (int?)t.CASH_IN_ID)) + 1;
                    OBJ_NCORE_TRN_CASH_IN_INFO.CASH_IN_ID = id;

//Inserting other value here

    Obj_nCoreEntities.NCORE_TRN_CASH_IN_INFO.Add(OBJ_NCORE_TRN_CASH_IN_INFO);
                    Obj_nCoreEntities.SaveChanges();

                    transactionScope.Complete();
            }
            catch (DbEntityValidationException dbEx)
            {
                transactionScope.Dispose();
                string inner = ExceptionExtendedMethods.GetDBInnerExceptions(dbEx);                   
                return inner;
            }
            catch (Exception ex)
            {
                transactionScope.Dispose();
                string inner4 = ExceptionExtendedMethods.GetInnerExceptions(ex);
                return inner4;
            }

        }

0 个答案:

没有答案