我们随机获得此异常,而谷歌搜索我发现这可能是由于框架问题...像服务包和所有....
以下是触发/执行LINQ TO SQL查询的通用函数
Public Shared Function Find(Of T As ActiveRecordBase)(ByVal id As Object) As ActiveRecordBase
Dim tableMetaData As MetaTable = GetTableMetadata(Of T)()
Dim sql As String = String.Format("SELECT * FROM {0} WITH (NOLOCK) WHERE {1} = ?", tableMetaData.TableName, GetPrimaryKeyName(Of T))
sql = sql.Replace("?", "{0}")
Return UnitOfWork.Current.ExecuteQuery(Of T)(sql, id).FirstOrDefault()
End Function
这是调用它的函数......
Public Shared Shadows Function Find(ByVal id As Integer) As Project
Return CType(ActiveRecordBase.Find(Of Project)(id), Project)
End Function
抛出异常 System.InvalidOperationException:结果中不存在必需的列'project_nbr'。 at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase
1.GetColumnOrdinals(NamedColumn[] namedColumns) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase
1..ctor(ObjectReaderSession1 session, NamedColumn[] namedColumns, Object[] globals, Object[] arguments, Int32 nLocals) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderSession
1.CreateReader [TObject](Func2 fnMaterialize, NamedColumn[] namedColumns, Object[] globals, Int32 nLocals, Boolean disposeDataReader) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderFactory
2.Create(DbDataReader dataReader,Boolean disposeDataReader ,IReaderProvider提供程序,Object [] parentArgs,Object [] userArgs,ICompiledSubQuery [] subQueries) 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.DataContext.ExecuteMethodCall(Object instance,MethodInfo methodInfo,Object [] parameters) at System.Data.Linq.DataContext.ExecuteQuery [TResult](String query,Object [] parameters) at GeneralMills.P2.ProjectTracking.Domain.ActiveRecordBase.Find [T](Object id) 在GeneralMills.P2.ProjectTracking.Domain.Project.Find(Int32 id) at GeneralMills.P2.ProjectTracking.Web.ProjectContext.GetCurrentDomainObject(Int32 key) 在GeneralMills.P2.ProjectTracking.Web.ContextBase.GetCurrentItem() 在GeneralMills.P2.ProjectTracking.Web.BaseContextPage.OnLoad(EventArgs e)