public IActionResult PostGroups(string name) { var Groups = new Groups() { Group_Name = name }; _context.Add(Groups); _context.SaveChanges(); return(Ok("Created")); }
public void Save() { _dbContext.SaveChanges(); }
static void Main(string[] args) { using (var context = new GroupsContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var maurycy = new User { Name = "Maurycy" }; var arthur = new User { Name = "Arthur" }; var andriy = new User { Name = "Andriy" }; var brice = new User { Name = "Brice" }; var smit = new User { Name = "Smit" }; var shay = new User { Name = "Shay" }; var jeremy = new User { Name = "Jeremy" }; var efTeam = new Group { Name = "EF Team" }; var queryTeam = new Group { Name = "Query Team" }; var managers = new Group { Name = "Managers" }; var engineers = new Group { Name = "Engineers" }; efTeam.Users.AddRange(new[] { maurycy, arthur, andriy, brice, smit, shay, jeremy }); queryTeam.Users.AddRange(new[] { maurycy, smit }); managers.Users.AddRange(new[] { arthur, jeremy }); engineers.Users.AddRange(new[] { maurycy, andriy, brice, smit, shay }); context.AddRange(maurycy, arthur, andriy, brice, smit, shay, jeremy, efTeam, queryTeam, managers, engineers); context.SaveChanges(); } using (var context = new GroupsContext()) { var users = context.Users.Include(e => e.Groups).ToList(); Console.WriteLine(); Console.WriteLine("ON.NET SHOW: EF Core 5.x Tour Many To Many Part 2"); Console.WriteLine(); Console.WriteLine("Users with Groups"); Console.WriteLine(); foreach (var user in users) { Console.WriteLine($"User: {user.Name}"); foreach (var group in user.Groups) { Console.WriteLine($" Group: {group.Name}"); } } } }
public void Save() { db.SaveChanges(); }