我正在使用EF 7构建一个ASP.NET 5 MVC应用程序 . 我有三个模型:The Book类:
public class Book : IBook, IHasThumbnail, IBugChecker
{
public Book()
{
Chapters = new List();
}
[Key]
public int ID { get; set; }
[Required]
public string Title { get; set; }
[Required]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
public string ThumbnailPath { get; set; }
public virtual IList Chapters { get; set; }
}
章节类:
public class MangaChapter : IChapter, IHasThumbnail
{
public MangaChapter()
{
PagesPath = new List();
}
[Key]
public int ID { get; set; }
[Required]
public string Title { get; set; }
public string ThumbnailPath { get; set; }
public IList PagesPath { get; set; }
public int BookID { get; set; }
public MangaBook Book { get; set; }
}
}
和路径类,我介绍的只是为了在EF中存储一个列表
public class Path
{
public Path(string s) { P = s; }
public int ID { get; set; }
public string P { get; set; }
public int MangaChapterID { get; set; }
public MangaChapter MangaChapter { get; set; }
public static implicit operator Path(string s)
{
return new Path(s);
}
public static implicit operator string(Path s)
{ return s.P; }
}
问题是当我尝试使用myDbContext访问数据库时,这样:
var list = _db.Paths.ToList();
我得到一个异常:ArgumentNullException:值不能为null . 参数名称:构造函数 . 我试图以不同的方式访问它,但总是以该异常结束 .
附:该应用程序的源代码完全在GitHub