我有两个实体:UserProfile 和 Inbox
这是我的代码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);
}
}
如何管理Inbox
和之间的这两种关系UserProfile
?