1

ASP.NET MVC + LINQ 例外に関連

ランダムに 8 ~ 12 回のページ リロードで 2 つの例外が発生します。どちらの例外もランダムで、1 番、2 番の可能性があります。例外は次のとおりです。

[IndexOutOfRangeException: Index was outside the bounds of the array.]
       System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i) +701
       System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i) +29
       Read_BoardMessage(ObjectMaterializer`1 ) +348
       System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +42
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
       Website.BusinessLogic.Services.BoardMessageService.GetBoardMessageModelsFromQuery(IQueryable`1 boardMessagesQuery) in D:\Applications\Website.BusinessLogic\Services\BoardMessageService.cs:167
       Website.BusinessLogic.Services.<>c__DisplayClass6.<GetStudentsBoardMessages>b__5() in D:\Applications\Website.BusinessLogic\Services\BoardMessageService.cs:89
       Library.Web.Utilities.RequestScopeCache.Get(String key, Func`1 defaultGetter) in D:\APPLICATIONS\Library\Web\Utilities\RequestScopeCache.cs:66
       Website.BusinessLogic.Services.BoardMessageService.GetStudentsBoardMessages(Int32 classId) in D:\Applications\Website.BusinessLogic\Services\BoardMessageService.cs:89
       Website.Web.usercontrols.ShowMessages.Initialize() in D:\Applications\Website.Web\usercontrols\ShowMessages.ascx.cs:28
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
       System.Web.UI.Control.LoadRecursive() +71
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

- - - と - - -

[InvalidOperationException: Sequence contains more than one element]
   System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +4539
   System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +207
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +500
   System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +41
   System.Linq.Queryable.Count(IQueryable`1 source) +352
   Website.Web.usercontrols.TopMenu.SetStudentMenu() in D:\Applications\Website.Web\usercontrols\TopMenu.ascx.cs:93
   Website.Web.usercontrols.TopMenu.IsLoggedIn() in D:\Applications\Website.Web\usercontrols\TopMenu.ascx.cs:60
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
  System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

スタック トレースは次のコードを指しています

using (var dataContext = new MyDataContext(Config.ConnectionString))
{
   int numberOfBoardMessages = dataContext.BoardMessages.
                Where(boardMessage => boardMessage.BoardMessageClasses.
      Any(boardMessageClass => boardMessageClass.ClassId == currentClassId) && boardMessage.IsPublished).
                    Count();
}

「BoardMessages」のない空のデータベースで試してみましたが、それでもエラーが発生します。何が問題なのか誰にも考えがありますか?

4

1 に答える 1

0

誰かが使用する必要があるように聞こえますTransactionScope

于 2012-09-27T09:05:42.190 に答える