投稿 コメント
+--------+ +--------+
| NID |<--+ | CID |
+--------+ | +--------+
| ... | | | ... |
+--------+ | +--------+
+--+ NID |
+--------+
投稿:コメント 1:0..n
ソース(伝言-cshtml)
ソース(伝言-model)
ソース(コメント-cshtml)
ソース(コメント-model)
|
public class NoticeDb : DbContext {
public DbSet<Notice> Notices {get; set;}
public DbSet<Comment> Comments {get; set;}
private string conStr = @"Server=・・・";
public NoticeDb() : base() {
}
public NoticeDb(string conStr) : base() {
this.conStr = conStr;
}
protected override void OnConfiguring(DbContextOptionsBuilder builder) {
builder
.UseMySql(conStr);
}
}
public class Notice {
[Key]
public int _id {get; set;}
public string Title { get; set; }
public string Author {get; set;}
public string Body {get; set;}
public DateTime Posted {get; set;}
public virtual IList<Comment> Comments {get; set;}
}
public class Comment {
[Key]
public int _id {get; set;}
public string Author {get; set;}
public string Body {get; set; }
public DateTime Posted { get; set; }
[ForeignKey("Notice")]
public int NoticeId {get; set;}
public virtual Notice Notice { get; set; }
}
|