I have a form that check it if a record already exists before it allows an insert. The problem i am having is that my deletes don’t delete they just hide. So know when I replace a deleted item it sees it already exists. How can i change my code to incorporate the Deleted Bool in the query it does to see if the record already exists.
My record has a attribute of Deleted and it is a bool. If the bool is true (record is deleted) i want it to insert. Otherwise return -1.
// Get Db context
ItemContext _db = new ItemContext();
bool ItemExists = _db.Item.Any(i => i.ItemName.Equals(ItemName));
if(ItemExists)
{
return -1;
}
else{
// Add product to DB.
_db.Item.Add(myItem);
_db.SaveChanges();
return myItem.ItemID;
}
//Success
Change your definition of
ItemExiststo include the notion of deleted: