FreeOZ论坛
标题:
Entity 外键问题求助
[打印本页]
作者:
xblues
时间:
23-4-2010 09:32
提示:
作者被禁止或删除, 无法发言
标题:
Entity 外键问题求助
请注意看下面两句红色的代码,第一行长的是书上的代码,第二行是我觉得也可以用的代码。
既然我从 item.CategoryId里面已经可以直接查到这个ID了,为什么作者却绕这么大一个弯路来得到这个CategoryID呢?
public ActionResult Details(int id)
{
Post item = dbentities.Posts.Where(i => i.Id == id).FirstOrDefault();
int categoryID = (int)item.CategoriesReference.EntityKey.EntityKeyValues.First(k => k.Key == "Id").Value;
//int categoryID = item.CategoryId;
string categoryName = (string)dbentities.Categories.First(m => m.Id == categoryID).Title;
ViewData["category"] = categoryName;
return View(item);
}
复制代码
作者:
xblues
时间:
23-4-2010 09:35
提示:
作者被禁止或删除, 无法发言
标题:
作者还加了这个链接注释
http://social.msdn.microsoft.com ... 6-a4dd-54e1c08958d9
欢迎光临 FreeOZ论坛 (https://www.freeoz.org/ibbs/)
Powered by Discuz! X3.2