我剛開始學asp.net MVC3型「ContextModule」我遇到這個問題:分析器錯誤信息:未能加載
我使用Visual Studio 2010,並有在編譯期間沒有錯誤,只有當我嘗試運行應用程序。 我正在Google上尋找答案,但沒有成功。 有誰知道如何解決這個問題?
謝謝!
EDIT-ContextModule代碼:
using System;
using System.Web;
namespace testbaza.Models
{
public class ContextModule : IHttpModule
{
internal const string CONTEXT_KEY = "datacontext";
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute);
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
private void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
if (HttpContext.Current.Session != null)
{
HttpContext.Current.Session[CONTEXT_KEY] = new EntitiesModel();
}
}
private void context_PostRequestHandlerExecute(object sender, EventArgs e)
{
CommitTransactions();
DisposeContext();
ClearSession();
}
private void CommitTransactions()
{
if (HttpContext.Current.Session == null)
{
return;
}
EntitiesModel dbContext =
HttpContext.Current.Session[CONTEXT_KEY] as EntitiesModel;
if (dbContext != null)
{
dbContext.SaveChanges();
}
}
private void DisposeContext()
{
if (HttpContext.Current.Session == null)
{
return;
}
EntitiesModel dbContext =
HttpContext.Current.Session[CONTEXT_KEY] as EntitiesModel;
if (dbContext != null)
{
dbContext.Dispose();
}
}
private void ClearSession()
{
if (HttpContext.Current.Session == null)
{
HttpContext.Current.Session.Remove(CONTEXT_KEY);
}
}
}
}
我已創建模塊和項目,如本視頻所示http://tv.telerik.com/watch/orm/building-a-mvc-3-application-database-first-with-openaccess-creating-model – user1598696
@ user1598696你能發佈ContextModule的源代碼嗎?只是爲了能夠檢查命名空間等? – Xharze
我已經發布我的代碼在編輯中,感謝您的幫助 – user1598696