This question is locked. New answers and comments are not allowed.
Hi,
I port MSSQL "Music Store" database to PostgreSQL database for testing MVC2. Now tables have primary keys and is type of SERIAL. Now when I add new record, exception is raised for duplicate key value! In reality, it is added to a record earlier in AlbumId field, value of 0. Now adding a new record also trying to enter the 0! How can I get OA ORM to do a sequence of key columns?
Here is code for new album :
And here is for adding :
Here is table definition :
Thanks, Michael.
I port MSSQL "Music Store" database to PostgreSQL database for testing MVC2. Now tables have primary keys and is type of SERIAL. Now when I add new record, exception is raised for duplicate key value! In reality, it is added to a record earlier in AlbumId field, value of 0. Now adding a new record also trying to enter the 0! How can I get OA ORM to do a sequence of key columns?
Here is code for new album :
// // GET: /StoreManager/Create public ActionResult Create() { var viewModel = new StoreManagerViewModel { Album = new Album(), Genres = storeDB.Genres.OrderBy(b => b.Name).ToList(), Artists = storeDB.Artists.OrderBy(c => c.Name).ToList() }; return View(viewModel); }And here is for adding :
// // POST: /StoreManager/Create [HttpPost] public ActionResult Create(Album album) { if (ModelState.IsValid) { // Save Album storeDB.Add(album); storeDB.SaveChanges(); return RedirectToAction("Index"); } else { // Invalid - Redisplay with errors var viewModel = new StoreManagerViewModel { Album = album, Genres = storeDB.Genres.OrderBy(b => b.Name).ToList(), Artists = storeDB.Artists.OrderBy(c => c.Name).ToList() }; return View(viewModel); } }Here is table definition :
CREATE TABLE "public"."Album" ( "AlbumId" SERIAL, "GenreId" INTEGER NOT NULL, "ArtistId" INTEGER NOT NULL, "Title" VARCHAR(160), "Price" NUMERIC(10,2) NOT NULL, "AlbumArtUrl" VARCHAR(1024) DEFAULT '/Content/Images/placeholder.gif'::character varying, CONSTRAINT "PK__Album__97B4BE370AD2A005" PRIMARY KEY("AlbumId"), CONSTRAINT "FK_Album_Genre" FOREIGN KEY ("GenreId") REFERENCES "public"."Genre"("GenreId") ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE, CONSTRAINT "FK__Album__ArtistId__276EDEB3" FOREIGN KEY ("ArtistId") REFERENCES "public"."Artist"("ArtistId") ON DELETE NO ACTION ON UPDATE NO ACTION NOT DEFERRABLE ) WITH OIDS; CREATE INDEX "ArtistId_idx_Album" ON "public"."Album" USING btree ("ArtistId"); CREATE INDEX "GenreId_idx_Album" ON "public"."Album" USING btree ("GenreId");Thanks, Michael.