Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Logic problem
Message
De
27/08/2014 04:44:02
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01606497
Message ID:
01606503
Vues:
66
This message has been marked as the solution to the initial question of the thread.
>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.
modifierGroup.Items.Select(x => x.ItemId == itemId)
will give an enumerable of Boolean values so .Any() will always be true. Try:
if (!modifierGroup.Items.Any(x => x.ItemId == itemId))
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform