I have a database sync job where I loop over 1000s of rows in XML and update DB tables with any changes found in the XML using EF4.1
My code is :
using (context = new MyDbContext())
{
foreach (var row in document.Elements("row"))
{
//DO UPDATING IN HERE.
//Part of which I call
var results = context.Set(type).SqlQuery("select top 1 * from " + type.Name + " where ExternalId=@p0", id); // this is the SQL running too long
return results.Cast<MyObject>().FirstOrDefault();
}
}
The "Select top 1..." query seems to be the one failing. What could be the problem. Should I have my context declared within the For Loop ?