private static void CreateData(MyContext context) { User user = new User() { Name = "Ori" }; Group group = new Group() { Name = "Friends", Users = new List<User>(), }; context.Groups.Add(group); group.Users.Add(user); context.SaveChanges(); }
private static void UpdateWithSelecting(MyContext context) { UserDTO dto = new UserDTO() { id = 2, name = "XXX", }; User user = new User() { ID = dto.id, }; DbEntityEntry entry = context.Entry(user); entry.State = EntityState.Unchanged; user.Name = dto.name; context.SaveChanges(); }
private static void AddMoreData(MyContext context) { //Group group = context.Groups.Where(g => g.Name == "Friends").Single(); Group group = (from g in context.Groups where g.Name == "Friends" select g).Single(); User user = new User() { Name = "Roni", }; group.Users.Add(user); context.SaveChanges(); }