public Agenda Get(Guid id) { using (FriendContext context = new FriendContext()) { Agenda agenda = context.Agendas.FirstOrDefault(a => a.Id == id); context.Entry(agenda).Reference(a => a.Owner).Load(); context.Entry(agenda).Collection(a => a.Contacts).Load(); return(agenda); } }
public void Modify(Agenda entity) { using (FriendContext context = new FriendContext()) { context.Entry(entity).State = EntityState.Modified; context.Entry(entity.Owner).State = EntityState.Modified; foreach (var contact in entity.Contacts) { context.Entry(contact).State = contact.Id.Equals(Guid.Empty) ? EntityState.Added : EntityState.Unchanged; } context.SaveChanges(); } }
public void Modify(User entity) { using (FriendContext context = new FriendContext()) { context.Entry(entity).State = EntityState.Modified; //context.Entry(entity.Owner).State = EntityState.Modified; foreach (var agenda in entity.Agendas) { context.Entry(agenda).State = agenda.Id.Equals(Guid.Empty) ? EntityState.Added : EntityState.Unchanged; } context.SaveChanges(); } }
public User Get(Guid id) { using (FriendContext context = new FriendContext()) { User user = context.Users.FirstOrDefault(a => a.Id == id); context.Entry(user).Collection(a => a.Agendas).Load(); //context.Entry(user).Collection(a => a.Contacts).Load(); return(user); } }