Mitchelln11
Active member
- Joined
- Apr 10, 2020
- Messages
- 39
- Programming Experience
- Beginner
Do you know why
I am running the REST call to save info to my Parks database, but before I save it, I am checking the park code to see if it's already in the database. Is this even the right code? It does hit the else statement, content just doesn't get updated, but rather creates a new one. Any ideas?
.Update
would be duplicating a record?I am running the REST call to save info to my Parks database, but before I save it, I am checking the park code to see if it's already in the database. Is this even the right code? It does hit the else statement, content just doesn't get updated, but rather creates a new one. Any ideas?
C#:
// Check for duplicates
Park uniqueParkCode = _context.Parks.Where(c => c.ParkCode == individualPark.ParkCode).FirstOrDefault();
if (uniqueParkCode == null)
{
_context.Parks.Add(park);
_context.SaveChanges();
}
else
{
_context.Parks.Update(park); // Adds a new park instead???
_context.SaveChanges();
}
Last edited by a moderator: