UserProfile と Inbox の 2 つのエンティティがあります。
これは私のコードですUserProfile
:
public partial class UserProfile {
public int Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
//--------------------------
public virtual ICollection<Messages.Inbox> Inboxes { get; set; }
}
public partial class UserProfile {
public static void Configure(DbModelBuilder mb) {
mb.Entity<UserProfile>().HasKey(up => up.Id);
}
}
そして、これは私のコードですInbox
:
public partial class Inbox {
public int Id { get; set; }
public int UserId { get; set; }//FK to userProfile
public Accounts.UserProfile User { get; set; }
public DateTime MessageDateTime { get; set; }
public string Context { get; set; }
public int SenderId { get; set; }//FK to userProfile
public Accounts.UserProfile Sender { get; set; }
}
public partial class Inbox {
public static void Configure(DbModelBuilder mb) {
mb.Entity<Inbox>().HasKey(up => up.Id);
mb.Entity<Accounts.UserProfile>().HasMany(up => up.Inboxes)
.WithRequired(p => p.User)
.HasForeignKey(p => p.UserId);
mb.Entity<Accounts.UserProfile>().HasMany(up => up.Inboxes)
.WithRequired(p => p.Sender)
.HasForeignKey(p => p.SenderId);
}
}
と の間のこれら 2 つの関係をどのように管理できInbox
ますUserProfile
か?