【发布时间】:2018-02-25 20:33:46
【问题描述】:
您好,我尝试做类似 PHP 的事情,即从数据库中检索数据并存储在二维集合(字典)中 我不确定我写的是否正确。
假设我的数据库表和预期的结构结果如下所示(见截图)
public ActionResult ShowBook()
{
var books = from v in db.Books
select v;
Dictionary<string, Dictionary<string, string>> test = new Dictionary<string, Dictionary<string, string>>();
foreach (var item in books)
{
test[item.Book_Type_ID][item.Author_ID] = item.Book_Name;
}
return .....
}
但我有这个错误
System.Collections.Generic.KeyNotFoundException:'给定的键不在字典中。'
我该怎么办?
【问题讨论】:
标签: c# asp.net database linq dictionary