我正在使用实体框架工作,并更新了一个表及其存储过程,但是当调用存储过程时,我收到以下错误。
The data reader is incompatible with the specified
‘FormValueModel.Valuation’. A member of the type,‘ValuationId’,does
not have a corresponding column in the data reader with the same name.
ValuationId是我想要自动递增的主要关键。
我可以从sql管理工作室执行存储过程查找,当我运行我的应用程序时,它会写入数据库,然后出现错误消息。
我不熟悉实体框架工作,只是具有基础知识,我认为这可能是来自model.edmx的映射问题。
在模型中重新创建和映射表和存储过程将是正确的过程?
储存程序。
ALTER PROCEDURE [dbo].[ValuationCreate] @TrackingNumber varchar(100),@FormMobiValuationId varchar(100),@ValuationPropertyId int,@ValuationFileName varchar(50) AS SET NOCOUNT ON SET XACT_ABORT ON DECLARE @ErrorMessage varchar(1000) BEGIN TRANSACTION --Insert to Valuation INSERT INTO [Valuation] ( TrackingNumber,FormMobiValuationId,ValuationPropertyId,-- new ValuationFileName,Date,ValuationStatus,IsActive ) VALUES ( @TrackingNumber,@FormMobiValuationId,@ValuationPropertyId,--new @ValuationFileName,GETDATE(),1,--Created 1 ) IF @@ERROR > 0 BEGIN SET @ErrorMessage = 'Valuation Insert Failed' GOTO ErrorHandler END ELSE BEGIN COMMIT TRANSACTION RETURN END ErrorHandler: RAISERROR(@ErrorMessage,16,1); ROLLBACK TRANSACTION RETURN -1
public ObjectResult<Valuation> ValuationCreate(global::System.String trackingNumber,global::System.String formMobiValuationId,Nullable<global::System.Int32> valuationPropertyId,global::System.String valuationFileName) { ObjectParameter trackingNumberParameter; if (trackingNumber != null) { trackingNumberParameter = new ObjectParameter("TrackingNumber",trackingNumber); } else { trackingNumberParameter = new ObjectParameter("TrackingNumber",typeof(global::System.String)); } ObjectParameter formMobiValuationIdParameter; if (formMobiValuationId != null) { formMobiValuationIdParameter = new ObjectParameter("FormMobiValuationId",formMobiValuationId); } else { formMobiValuationIdParameter = new ObjectParameter("FormMobiValuationId",typeof(global::System.String)); } ObjectParameter valuationPropertyIdParameter; if (valuationPropertyId.HasValue) { valuationPropertyIdParameter = new ObjectParameter("ValuationPropertyId",valuationPropertyId); } else { valuationPropertyIdParameter = new ObjectParameter("ValuationPropertyId",typeof(global::System.Int32)); } ObjectParameter valuationFileNameParameter; if (valuationFileName != null) { valuationFileNameParameter = new ObjectParameter("ValuationFileName",valuationFileName); } else { valuationFileNameParameter = new ObjectParameter("ValuationFileName",typeof(global::System.String)); } return base.ExecuteFunction<Valuation>("ValuationCreate",trackingNumberParameter,formMobiValuationIdParameter,valuationPropertyIdParameter,valuationFileNameParameter); }