Oracle
 sql >> Database >  >> RDS >> Oracle

Genera identità per un database Oracle tramite Entity Framework utilizzando una stored procedure esistente

1) Crea sequenza in Oracle

 CREATE SEQUENCE dummy_test_seq
  MINVALUE 1
  MAXVALUE 999999999999999999999999999
  START WITH 1
  INCREMENT BY 1;

2)Crea proprietà

   sealed public class CommonUtilities
    {
      #region Sequences
       public static int DummyTestSeq
        {
         get
          {              
            using (Entities ctx = new Entities()) 
             { 
               return Convert.ToInt32(ctx.Database.SqlQuery<decimal>("SELECT dummy_test_seq.NEXTVAL FROM DUAL").ToList().Single()); 
              }  
            }
         }
    #endregion
}

3)Sequenza di acquisizione

   public int InsertTable1()
    {
      using (Entities ctx = new Entities())
        {
            ctx.tabel1.Add(new tabel1()
            {
                SEQ = CommonUtilities.DummyTestSeq,
                Date= DateTime.Now
            });
            return ctx.SaveChanges();
        }
     }