从对象类型System.RuntimeType到已知的托管提供程序本机类型不存在映射。执行存储过程

时间:2018-07-06 17:11:22

标签: c# entity-framework

我收到此错误:

  

不存在从对象类型System.RuntimeType到已知托管提供程序本机类型的映射

当我尝试从存储过程中获取结果时。

这是存储过程的定义:

ALTER  PROCEDURE [dbo].[usp_getDieDetails]
    (@pbID INT, 
     @id INT = NULL)
AS
    --EXEC usp_getDieDetails @pbID = null, @id = 594
    IF @id IS NULL
    BEGIN
        SELECT *
        FROM tbl_die
        WHERE productBuildID = @pbID
        ORDER BY 1
    END
    ELSE
    BEGIN
        SELECT *
        FROM tbl_die
        WHERE dieID = @id
        ORDER BY 1
    END

这是执行此存储过程的结果:

enter image description here

我的课堂上有一个方法继承自DbContext

public virtual usp_getDieDetails_Result usp_getDieDetails(Nullable<int> pbID, Nullable<int> id)
{
    var pbIDParameter = pbID.HasValue ?
        new SqlParameter("pbID", pbID) :
        new SqlParameter("pbID", typeof(int));

    var idParameter = id.HasValue ?
        new SqlParameter("id", id) :
        new SqlParameter("id", typeof(int));

    var result = this.Database.SqlQuery<usp_getDieDetails_Result>("exec usp_getDieDetails @pbID @id", new[] { pbIDParameter, idParameter });

    return result.SingleOrDefault();
}

这是我的usp_getDieDetails_Result类定义(与我的表tbl_die相同的定义):

public partial class usp_getDieDetails_Result
{
        public int dieID { get; set; }
        public int productBuildID { get; set; }
        public Nullable<int> diePosition { get; set; }
        public Nullable<decimal> dieSizeWt { get; set; }
        public Nullable<decimal> dieSizeLt { get; set; }
        public Nullable<int> dieThicknessID { get; set; }
        public Nullable<int> diePreparationID { get; set; }
        public Nullable<int> dieAttachTypeID { get; set; }
        public Nullable<int> epoxyTypeID { get; set; }
        public Nullable<int> filmTypeID { get; set; }
        public string filmTypeThickness { get; set; }
        public Nullable<int> bondMetalID { get; set; }
        public Nullable<int> siliconTechID { get; set; }
        public Nullable<int> waferDiaID { get; set; }
        public Nullable<int> waferSawProcessID { get; set; }
        public Nullable<decimal> bondOpenLt { get; set; }
        public Nullable<decimal> bondOpenWt { get; set; }
        public Nullable<decimal> bondPitch { get; set; }
        public string polyimide { get; set; }
        public Nullable<System.DateTime> lastMod { get; set; }
        public string idsid { get; set; }
        public Nullable<decimal> scribeWidth { get; set; }
        public Nullable<decimal> dieOffsetY { get; set; }
        public Nullable<decimal> dieOffsetX { get; set; }
}

但是,每次执行此方法时,都会出现问题标题中的错误。我的代码中缺少什么?

任何帮助或反馈将不胜感激。

这是堆栈跟踪:

at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)
   at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
   at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
   at System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters, Boolean includeReturnValue)
   at System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69`1.<ExecuteStoreQueryReliably>b__68()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69`1.<ExecuteStoreQueryReliably>b__67()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, ExecutionOptions executionOptions, Object[] parameters)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass14`1.<ExecuteSqlQuery>b__13()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at SubconTechDB.DAL_EF.SubconTechDBModel.usp_getDieDetails(Nullable`1 pbID, Nullable`1 id) in C:\Users\asandiX\Documents\SubconTechDB v2\SubconTechDb\SubconTechDB\DAL_EF\spDefinitionsWrapper.cs:line 565
   at SubconTechDB.Controllers.SiliconController.Edit(Int32 pbID, Int32 id, String product, String site, String package) in C:\Users\asandiX\Documents\SubconTechDB v2\SubconTechDb\SubconTechDB\Controllers\SiliconController.cs:line 112
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()

0 个答案:

没有答案