【发布时间】:2013-12-19 05:01:03
【问题描述】:
假设我有两个实体,User 和 Notification:
public class User
{
[Key]
public int UserId { get; set; }
// other public properties
// Navigation Properties
public virtual ICollection<Notification> Notifications { get; set; }
}
public class Notification
{
[Key]
public int NotificationId { get; set; }
// other public properties
// Navigation Properties
public virtual ICollection<User> Users { get; set; }
}
我只是像这样添加many-to-many 关系:
modelBuilder.Entity<User>()
.HasMany(u => u.Notifications)
.WithMany(t => t.Users)
.Map(m =>
{
m.ToTable("UserNotifications");
m.MapLeftKey("UserId");
m.MapRightKey("NotificationId");
});
但是,如果我想在这个名为 'Status' 的表中添加额外的列,会发生什么?我以为我可以使用AddColumn,但是我怎样才能访问此列并获得它的价值?我怎样才能做到这一点?我想检查用户是否阅读了通知。任何建议都会很棒,谢谢。
【问题讨论】:
-
不确定我是否理解您为什么不能只添加列并对其进行映射? ...
-
我对 Fluent API 和映射了解不多,我只是对如何从我的上下文中访问该列感到困惑
标签: c# entity-framework ef-code-first entity-relationship