相关疑难解决方法(0)

来自EF映射对象的不兼容的数据读取器异常

我正在使用实体框架并更新了一个表及其存储过程,但是在调用存储过程时出现以下错误.

数据读取器与指定的"FormValueModel.Valuation"不兼容.类型为"ValuationId"的成员在数据读取器中没有具有相同名称的相应列.

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); …
Run Code Online (Sandbox Code Playgroud)

mapping asp.net-mvc entity-framework model

24
推荐指数
3
解决办法
5万
查看次数

什么可以导致EntityCommandDefinition.ExecuteStoreCommands中的EntityCommandExecutionException?

从SQL Server 2008数据库运行的C#程序中的SQL Server视图中选择字段的特定LINQ-to-SQL查询,该数据库在我的本地开发环境中运行正常,在暂存环境中运行时会产生异常:

Exception Message: An error occurred while executing the command definition. See the inner exception for details. 

Exception Trace: System.Data.Entity.Core.EntityCommandExecutionException 
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) 
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) 
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) 
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.b__5() 
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) 
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
at System.Data.Entity.Core.Objects.ObjectQuery`1..GetEnumerator>b__0() 
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() 
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
at [my code ...] 
Run Code Online (Sandbox Code Playgroud)

导致此异常的原因是什么?

c# sql-server linq-to-sql

22
推荐指数
2
解决办法
4万
查看次数

数据读取器与指定的实体框架不兼容

我有一个方法,将从sproc返回裸min结果以填充选择菜单.当我想要裸min结果时,我将bool getMin = true传递给sproc,当我想要完整记录时,我传递bool getMin = false.

这导致Entity FrameWork错误" 数据读取器与指定的不兼容 "

错误最相关的部分

{"Message":"发生错误.","ExceptionMessage":"数据读取器与指定的'CatalogModel.proc_GetFramingSystems_Result'不兼容.类型的成员'FrameType'在其中没有相应的列具有相同名称的数据读取器.","ExceptionType":"System.Data.EntityCommandExecutionException",

显然,错误告诉我,当数据读取器尝试设置不在查询结果中的属性"FrameType"时.

现在我理解了这个错误,我想知道的是,我正在为了将这个sql sproc拆分成两个sprocs而进行goning,还是有解决方法?

我的功能如下

public static IEnumerable<IFramingSystem> GetFramingSystems(int brandID, string frameType, string glazeMethod, bool getMin)
{
    using (CatalogEntities db = new CatalogEntities())
    {
        return db.proc_GetFramingSystems(brandID, frameType, glazeMethod, getMin).ToList<IFramingSystem>();
    };
}
Run Code Online (Sandbox Code Playgroud)

我的TSQL如下

ALTER proc [Catelog].[proc_GetFramingSystems]
@BrandID   INT,
@FrameType VARCHAR(26),
@GlazeMethod VARCHAR(7) ='Inside',
@getMin    BIT = 0
as
BEGIN
SET NOCOUNT ON;
IF @getMin =0
BEGIN
SELECT c.ID,c.Name,c.Descr,c.FrameType,c.isSubFrame,
       c.GlassThickness,c.GlassPosition,c.GlazingMethod,c.SillProfile
        from Catelog.Component c
WHERE c.MyType ='Frame' 
AND c.FrameType = @FrameType …
Run Code Online (Sandbox Code Playgroud)

.net c# t-sql entity-framework-4

15
推荐指数
2
解决办法
6万
查看次数