我有一个全局数据上下文,我会更新每个请求:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
Response.Write(GetResponse());
Response.End();
}
public string GetResponse()
{
string fileName = this.Page.Request.PathInfo;
fileName = fileName.Remove(0, fileName.LastIndexOf("/") + 1);
DataContext.Renew();
MethodInfo method = this.GetType().GetMethod(fileName);
if (method == null)
throw new InvalidOperationException(
string.Format("Unknown method {0}.", fileName));
return (string)method.Invoke(this, new object[0]);
}
但无论出于何种原因,通常当我收到多个请求(如多个 ajax 调用)时,我会收到如下错误:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Data.Linq.DataContext.GetTable(MetaTable metaTable)
at System.Data.Linq.DataContext.GetTable[TEntity]()
at LibKezberProjectManager.KezberPMDBDataContext.get_Cases() in c:\Users\jlarouche\Documents\Visual Studio 2012\Projects\KezberProjectManager\LibKezberProjectManager\KezberPMDB.designer.cs:line 204
at LibKezberProjectManager.Data.Cases.GetAllScheduled() in c:\Users\jlarouche\Documents\Visual Studio 2012\Projects\KezberProjectManager\LibKezberProjectManager\Data.cs:line 113
at LibKezberProjectManager.Logic.ScheduleManager.GetScheduledCases() in c:\Users\jlarouche\Documents\Visual Studio 2012\Projects\KezberProjectManager\LibKezberProjectManager\Logic.cs:line 1035
at KezberProjectManager.CalendarServices.GetDates() in c:\Users\jlarouche\Documents\Visual Studio 2012\Projects\KezberProjectManager\KezberProjectManager\CalendarServices.aspx.cs:line 628
我更新了每个请求的上下文,它只用于那个请求。难道我做错了什么?
DataContext.Renew() 调用 db = new KezDBContext();
所有电话都使用这个。
我所有的访问器方法都是静态的这一事实会是一个问题吗?我不会这么认为。
谢谢