Note that there are some explanatory texts on larger screens.

plurals
  1. POEF Requiring primary key when creating a new entry in sql table
    primarykey
    data
    text
    <p>So we have a number of tables in our edmx, 13, that we created from an existing sql database. When we try to add a new entry to the tables through the UI we built, it fails on all but 4 of them. </p> <p>Doing some digging we found out the the ModelState actually comes back as false and it is because we get an error that states "The [PrimaryKeyId] field is required". I don't understand what would be causing this issue when some of the tables are working just fine when we add new data. </p> <p><img src="https://i.stack.imgur.com/Z5Qn6.png" alt="enter image description here"></p> <p>In the edmx we looked at the properties of the primary keys of the tables and everything seems right</p> <p><img src="https://i.stack.imgur.com/UTms2.png" alt="enter image description here"></p> <p>I feel like there could have been an issue when scaffolding the tables. I cannot be sure, I am still learning the intricacies of EF.</p> <p>Can anyone point me in the right direction? Could this be something on the SQL side (personaly don't think it is as we already added data in these tables through sql scripts)? Could it be EF? Should I blow the edmx tables again and re-add them? I am feeling lost. Thanks for the help!</p> <p><strong>EDIT 1</strong></p> <p>So because we used the Entity Framework Scaffolding we have the basic methods. This is the create method with a few properties being manually set. Also the Primary Keys in the db are auto incrementing.</p> <pre><code>[HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(Entity entity) { if (ModelState.IsValid) { _user = GetUser(); entity.CreateDate = DateTime.Now; entity.LastUpdateDate = DateTime.Now; entity.LastUpdatedById = _user.Id; entity.CreatorId = _user.Id; db.Entities.Add(entity); db.SaveChanges(); return RedirectToAction("Index"); } return View(entity); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload