Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Logic problem
Message
De
27/08/2014 13:23:55
 
 
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:
01606562
Vues:
37
>>>>>I need to process all missing Ids. I think this code will only get one of them.
>>>>
>>>>Oops:
foreach (var i in itemIds.Where(x => modifierGroup.Items.All(y => y.ItemId != x)))
>>>>            {
>>>>                //Use i here
>>>>            }
>>>
>>>So, to be absolutely sure, these two are the same, but the first form is better, right?
>>>
>>>
>>>List<int> itemIds = connection.Query<int>(currentItemsQuery, new { ModGrpId = modifierGroup.GroupId }, transaction).ToList();
>>>                // Delete list
>>>                foreach (var id in itemIds.Where(x => modifierGroup.Items.All(y => y.ItemId != x)))
>>>                {
>>>                    rowsAffected = connection.Execute(this.deleteQuery, new { ModGrpId = modifierGroup.GroupId, ItemID = id }, transaction);
>>>                }
>>>
>>>                // Delete list
>>>                foreach (var itemId in itemIds)
>>>                {
>>>                    if  (!modifierGroup.Items.Any(x => x.ItemId == itemId))
>>>                    {                        
>>>                        rowsAffected = connection.Execute(this.deleteQuery, new { ModGrpId = modifierGroup.GroupId, ItemID = itemId }, transaction);
>>>                    }
>>>                }
I think so - but untested.....
>
>I haven't tested yet, but I think it does work differently - the first version (yours) will execute 1 select statement and the second version will execute as many as we have Ids.

Why not test it and then tell me what you think :-}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform