using System.Data.Entity;
public static void Main()
using (var context = new EntityContext())
context.GroupMemberships.Add(new GroupMembership { ArchivedDate = DateTime.Now, Changed = false, EntryStamp = DateTime.Now});
context.GroupMemberships.Add(new GroupMembership { Changed = false , EntryStamp = DateTime.Now});
using (var context = new EntityContext())
FiddleHelper.WriteTable("Data Before Update", context.GroupMemberships.ToList());
using (var context = new EntityContext())
var groupIds = context.GroupMemberships.Select(x => x.Id).ToList();
.Where(x => !x.ArchivedDate.HasValue && groupIds.Contains(x.Id))
.UpdateFromQuery(x => new GroupMembership() { Changed = true });
using (var context = new EntityContext())
FiddleHelper.WriteTable("Data After Update", context.GroupMemberships.ToList());
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<GroupMembership> GroupMemberships { get; set; }
public class GroupMembership
public int Id { get; set; }
public int GroupId { get; set; }
public int UserId { get; set; }
public bool Changed { get; set; }
public System.DateTime EntryStamp { get; set; }
public Nullable<System.DateTime> ArchivedDate { get; set; }