0

Problem :

  • If I make STOREGENERATED PATTERN = NONE Record is inserted in my database once with ID =0. After that it gives error so I change it to identity

    enter image description here

  • I wanted to automatically generate primary key. I created a new project made it Identity

      public partial class USER
    {
    [key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }
    public string NAME { get; set; }
    }
    

Controller

        public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Index(USER obj)
    {
       using( var db = new Entities() )
       {
           var u = new USER();
           u.NAME = obj.NAME;
           db.USERS.Add(u);
           db.SaveChanges();
       }

        return View();
    }

ERROR!

enter image description here

I search on the internet but could not make it work. --> I want my project to automatically create Primary key of tables. I am using Oracle SQL database and Entity framework 5.0.0

Rohaitas
  • 84
  • 1
  • 12
  • how can I tell oracle? the data is indeed inserted in Oracle once if I make store generated pattern to NONE – Rohaitas May 16 '17 at 14:36

1 Answers1

1

You've changed the EDMX, but that's just a model of your database. It doesn't change the database by itself.

Configure the column so it actually is generated by the server: How to create id with AUTO_INCREMENT on Oracle?.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272