Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Table relations of the EF model error

$
0
0

Good day, I'm new to ASP.NET MVC and I'm trying to make a simple application where I only have two tables, the first table is the author and the second is the table books. When I register an author, he saves it in the database, but when I want to register a book, he marks me an error.

System.Data.Entity.Infrastructure.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.'

InvalidOperationException: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'Id'.

I have a foreign key that refers to authors in the book table:

Id_autor int foreign key references autor(ID)

And this is the POST method

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,nombrelibro")] libros libros)
        {
            if (ModelState.IsValid)
            {
                db.libros.Add(libros);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Id = new SelectList(db.autor, "Id", "nombre", libros.Id);
            return View(libros);
        }

I hope you can help me, thanks!


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>