我是新来的,已经在这里工作了很长时间,我无法解决问题。我的 ShowAllReview 控制器中有以下代码:
public ActionResult Index(string Ordering, string WordFilter, string DisplaySearchResults, int? CounterForPage)
{
using (var db = new gamezoneDBEntities())
{
ViewBag.Message = TempData["message"];
ViewBag.CurrentSort = Ordering;
ViewBag.NameSortParm = String.IsNullOrEmpty(Ordering) ? "GameName" : "";
ViewBag.DateSortParm = Ordering == "ReleaseYearOfGame" ? "DiscriptionOfGame" : "Date";
{
TempData["DisplaySearchResult"] = DisplaySearchResults;
{
ViewBag.search = DisplaySearchResults;
}
if (Request.HttpMethod == "GET")
{
DisplaySearchResults = WordFilter;
}
else if (DisplaySearchResults == "")
{
ViewData["MyMessage"] = "Nothing Has Been Entered.";
}
else
{
CounterForPage = 1;
}
ViewBag.CurrentFilter = DisplaySearchResults;
var FullDatabaseItem = from b in db.tblReviews.Include(x => x.tblGame)
select b;
if (!String.IsNullOrEmpty(DisplaySearchResults))
{
FullDatabaseItem = FullDatabaseItem.Include (x => x.tblGame)
.Where (b => b.Score.ToUpper().Contains(DisplaySearchResults.ToUpper()));
}
switch (Ordering)
{
case "HeadlineName":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.Score);
break;
case "DatePosted":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.Recomendation);
break;
case "DiscriptionDate":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.Recomendation);
break;
default:
FullDatabaseItem = FullDatabaseItem.OrderByDescending(b => b.Recomendation);
break;
}
int pageSize = 3;
int pageNumber = (CounterForPage ?? 1);
var PageNumberResults = FullDatabaseItem.ToPagedList(pageNumber, pageSize);
ViewBag.PageNumberResults = FullDatabaseItem.Count();
if (PageNumberResults.Any())
{
return View(PageNumberResults);
}
return View("ErrorView");
}
}
}
如您所见,我添加了以下代码:
var FullDatabaseItem = from b in db.tblReviews.Include(x => x.tblGame)select b;
如果没有评论表中的包含,视图将引发以下错误:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
现在问题出在这行代码上:
FullDatabaseItem = FullDatabaseItem.Include (x => x.tblGame)
.Where (b => b.Score.ToUpper().Contains(DisplaySearchResults.ToUpper()));
我正在尝试获取游戏名称,因此当用户使用我的搜索时,他只需输入游戏名称即可获得唱片购买。但是正如您所看到的,正在搜索的字段"Score"
是 tblReview 字段,因为我需要的字段"GameName"
不会在那里工作,因为它说它不存在。
我需要帮助来解决问题
您需要任何更多信息,请询问我,我会提供
谢谢你