0
をidentitymodelするためにカスタムフィールドを追加し、私はMVCのアイデンティティモデルに新しいフィールドを追加した
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;
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int AccountID { get; set; }
public int JeAdmin { get; set; }
public Ekipa Ekipa { get; set; }
}
マイekipaクラスには、次の要素で構成されます
私は私のオブジェクトを設定するにはどうすればよい public class Ekipa
{
public int id { get; set; }
public string Ime { get; set; }
public int LeaderID { get; set; }
public int Geslo { get; set; }
}
ログインしたユーザーにデータベースから取得しますか? 私は、現在のユーザーを取得し、
ApplicationDbContext db = new ApplicationDbContext();
var currentUserId = User.Identity.GetUserId();
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
EkipaDb db1 = new EkipaDb();
currentUser.Ekipa = db1.Ekipa.Where(m => m.id == 1);
は、どのように私はidが1であるEkipaDbからオブジェクトを取得し、現在のユーザーにそれを追加するには?
ありがとうございます。私はそれが何とかMVCで可能だと思った。 :) – Ashley
MVCよりもエンティティフレームワークが大好きです。 –