我在以下代码行中遇到了随机错误(每100个页面加载中有1个):
topic = TopicsContext.GetCurrentDataContext().tTopics.Where(t => t.ContentId == contentId).SingleOrDefault();
ContentId属性和contentId本地变量都是long类型。
最重要的是,错误是随机发生的,在大多数情况下它能正常工作。
感谢您的建议。
以下是完整的异常信息:
Error Message: Specified cast is not valid.
Error Source: System.Data.Linq
Error Stack Trace:
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
at Topics.BusinessLogic.Models.Services.TopicService.GetTopic(String title) in C:\rabota\topics\source\trunk\Topics.BusinessLogic\Models\Services\TopicService.cs:line 65