嘿,我在这样的应用程序中添加了团队:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public virtual ICollection<Function> Functions { get; set; }
public virtual ICollection<Participation> Participations { get; set; }
public virtual ICollection<Team> Teams { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Mobile { get; set; }
public DateTime Birthdate { get; set; }
}
在我的控制器中,我想为用户添加一个新团队:
ApplicationUser user = UserManager.GetUserById(dto.PersonId[0]);
if (user != null)
{
if (user.Teams == null)
{
user.Teams = new List<Team>();
}
user.Teams.Add(mannschaft);
mannschaft.UsersId.Add(user?.Id);
uow.SaveChanges();
Team team = uow.RepTeam.Get(t => t.Bezeichnung == dto.Name).FirstOrDefault();
return Request.CreateResponse(HttpStatusCode.Created, team?.Id);
}
因此,没有问题将团队添加到IdentityUser中,但是当我想在其他控制器中致电所有团队时:
ApplicationUser user = UserManager.GetUserById(userid);
ICollection<DtoTeam> foo = new List<DtoTeam>();
if (user != null)
{
foreach (var teams in user.Teams)
{
foo.Add(uow.RepTeam.GetByKey(teams).ToDto());
}
}
return foo;
它说用户中没有团队...
imo,您仍然可以使用表格并删除aspnet ..表或其他任何
的自动表,如果要保存数据,则可以使用onModeLcreating((
将像IdentityUser这样的路径更改为表格protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("your_table_name");
}
任何进步都可以搜索Google