我是新來的,在這裏已經很久了,我無法解決問題。我有下面的代碼在我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"
在那裏不起作用,因爲它表示它不存在。
我需要幫助解決問題
任何您需要了解更多信息請諮詢我,我應提供
謝謝
我剛剛收到這個答案會試圖暗示它到我的,看看我得到什麼結果。將提醒ou的結果,謝謝你的回答 – user1319420 2012-04-14 13:39:37
非常感謝你的工作:)你最好的我一直在這個很長時間,並得到它的工作:) – user1319420 2012-04-14 13:51:37