示例#1
0
 public async Task NullifyExpertRelation(Func <IQueryable <Lead>, IQueryable <Lead> > queryBuilder)
 {
     using (DbContext context = DbContextManager.BuildNewContext())
     {
         List <Lead> leads = EntityFrameworkQueryableExtensions.AsNoTracking(queryBuilder(context.Set <Lead>())).ToList();
         foreach (var lead in leads)
         {
             Lead stubLead = new Lead()
             {
                 Id = lead.Id, ExpertId = null
             };
             context.Set <Lead>().Attach(stubLead);
             context.Entry(stubLead).Property(x => x.ExpertId).IsModified = true;
         }
         await context.SaveChangesAsync();
     }
 }