我试图弄清楚如何为通知建模。这是我尝试过的。
public class NotificationType
{
public int NotificationTypeID { get; set; }
public string Type { get; set; }
public string Action { get; set; }
}
public class Notification
{
public int NotificationID { get; set; }
public bool ReadStatus { get; set; }
public DateTime DateCreated { get; set; }
[ForeignKey("User")]
public int UserID { get; set; }
[ForeignKey("NotificationType")]
public int NotificationTypeID { get; set; }
public int CommentID { get; set; }
public int ProjectID { get; set; }
public Comment Comment { get; set; }
public Project Project { get; set; }
public NotificationType NotificationType { get; set; }
public User User { get; set; }
}
坦率地说,我觉得我仍然不知道自己在做什么,但是让我告诉你我想做什么,如果这是一个坏主意,请告诉我,如果不是,请告诉我我是如何做到的。
我有Notifications
用于与 a 相关的操作Comment
,Reply
并且Project
- 这就是我拥有所有这些导航属性和字段的原因。我想基本上使用NotificationType
来确定它是什么,然后使用适当的 ID 字段来获取信息以向用户显示通知。
第一个问题,我似乎无法将这些 ID ( CommentID
ProjectID
) 字段设为 Nullable,因此我不必总是拥有它们。
如何使用数据注释和/或流利的 api 使它们可以为空,或者更好地设计我的模型?