There are other questions on SO about this but it's my first time and I'm failing to completely comprehend.
QUESTION 1: Assuming this example is actually safe, i.e. the warning could be ignored: How would this code need to be changed so that the problem this warning warns about will be real?
QUESTION 2: How is it that the fix applied for the warning makes the warning go away? My intuition tells me it is the same result.
Here's the code:
public static void SynchCreativesForCampaign(int pid, ILogger logger)
{
var db = new SynchDbDataContext(true);
foreach (var creativeItem in CreativeList.Create(pid).CreativeItems)
{
logger.Log(@"creative id " + creativeItem.CreativeId);
var creativeDetail = CreativeDetail.Create(creativeItem.CreativeId);
//var item = creativeItem; <-- this gets added by the "fix" for the warning
var creativeEntity = (from c in db.CreativeEntities
where c.dtid == creativeItem.CreativeId
select c).FirstOrDefault();
if (creativeEntity == null)
{
creativeEntity = new CreativeEntity {dtid = item.CreativeId};
db.CreativeEntities.InsertOnSubmit(creativeEntity);
}
}
db.SubmitChanges();
}
Here's the warning: