Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Logic problem
Message
From
27/08/2014 13:23:55
 
 
To
27/08/2014 13:19:59
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01606497
Message ID:
01606562
Views:
36
>>>>>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 :-}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform