Just replace this code in the code:
foreach (Property P in Results) { if(P.PropertyId==0 && P.EntityState==EntityState.Added) { var id = Repository.Properties.Max(p => (int?)p.PropertyId) ?? 0; P.PropertyId=++id; Repository.Properties.AddObject(P); Repository.SaveChanges(); } }
of course, in the first line of the add file:
using System.Linq;
for multithreaded processing:
foreach (Property P in Results) { if(P.PropertyId==0 && P.EntityState==EntityState.Added) { while(true){ try{ var id = Repository.Properties.Max(p => (int?)p.PropertyId) ?? 0; P.PropertyId=++id; Repository.Properties.AddObject(P); Repository.SaveChanges(); break; }catch{ continue; } } } }
of course, first create a new instance of the 'property' object, then assign the field to the field variable, then call AddObject and SaveChanged!
source share