Hi everybody,
The original code didn't work and I adjusted it this way, but now it also doesn't work correctly.
Here is the code
foreach (var itemId in itemIds)
{
if (!modifierGroup.Items.Select(x => x.ItemId == itemId).Any())
{
const string deleteQuery = "DELETE FROM [dbo].[ModGrpLnk] WHERE ModGrpId = @ModGrpId AND ItemID = @ItemID";
rowsAffected = connection.Execute(deleteQuery, new { ModGrpId = modifierGroup.GroupId, ItemID = itemId }, transaction);
}
}
itemIds is a list of 5 items. modifierGroup.Items have 4 items (so one Id is missing and I want to delete that row from the database).
modifierGroup.Items has list of items entries (Items have ItemId among other properties).
So, I want to delete the record if the itemId from itemIds array is not found in the modifierGroup.Items list. My current code doesn't delete anything at all.
What may be the problem here?
Thanks in advance.
If it's not broken, fix it until it is.
My Blog