public void Create(UserModel model) { var user = mapper.ToEntity(model); dataContext.Users.Add(user); user.Roles = model.Roles?.Select(e => { return(new UserRole() { RoleId = e.RoleId }); }).ToList(); dataContext.SaveChanges(); model.Id = user.Id; }