数据读取器是指定的实体框架不兼容 [英] The data reader is incompatible with the specified Entity Framework

查看:2645
本文介绍了数据读取器是指定的实体框架不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个会从一个存储过程返回裸分成果填补一个选择菜单的方法。当我想要的裸分成绩我通过布尔getMin =真到了存储过程,而当我想完整记录我通过布尔getMin =假的。

这是造成实体框架错误数据读取器不兼容指定

错误的最相关的部分

  

{消息:发生了一个错误。,ExceptionMessage:数据读取器是指定的CatalogModel.proc_GetFramingSystems_Result类型的成员,帧类型不兼容,不具有相应的在数据读取器具有相同名称的列,ExceptionType。:System.Data.EntityCommandExecutionException,

显然错误是告诉我,当数据读取器试图设置属性帧类型这是不是在查询结果。

现在我理解错误,我所想知道的是,我在goni​​ng个人有T分裂这个SQL存储过程分为两个存储过程或者是有一个工作围绕这个?

我下面的功能

 公共静态的IEnumerable< IFramingSystem> GetFramingSystems(INT brandID,串帧类型,字符串glazeMethod,布尔getMin)
{
    使用(CatalogEntities DB =新CatalogEntities())
    {
        返回db.proc_GetFramingSystems(brandID,帧类型,glazeMethod,getMin).ToList< IFramingSystem>();
    };
}
 

我下面的TSQL

ALTER PROC [Catelog]。[proc_GetFramingSystems] @BrandID INT, @FrameType VARCHAR(26), @GlazeMethod VARCHAR(7)='内部', @getMin位= 0 如 开始 SET NOCOUNT ON; 如果@getMin = 0 开始 选择c.ID,c.Name,c.Descr,c.FrameType,c.isSubFrame,        c.GlassThickness,c.GlassPosition,c.GlazingMethod,c.SillProfile         从Catelog.ComponentÇ WHERE c.MyType =框架 与c.FrameType = @FrameType 与c.GlazingMethod = @GlazeMethod 和c.ID IN( 选择cp.ComponentID从Catelog.Part p JOIN             Catelog.ComponentPart CP ON p.ID = cp.PartID             WHERE p.BrandID = @BrandID             )             ORDER BY c.Name 结束 其他 SELECT c.ID,c.Name,c.Descr         从Catelog.ComponentÇ WHERE c.MyType =框架 与c.FrameType = @FrameType 与c.GlazingMethod = @GlazeMethod 和c.ID IN( 选择cp.ComponentID从Catelog.Part p JOIN             Catelog.ComponentPart CP ON p.ID = cp.PartID             WHERE p.BrandID = @BrandID             )             ORDER BY c.Name SET NOCOUNT OFF; 结束;

解决方案

在我看来,如果返回不同的数据,第一支回报9列的两个分支其中第二 - 只有三个。我相信EF不能从后者反映了 IFramingSystem 。具体来说,列帧类型(和其他5列)明显缺失的:

  ...
 选择c.ID,c.Name,c.Descr<  - 在哪里其余列
    从Catelog.ComponentÇ
 ...
 

I have a method that will return the bare min results from a sproc to fill a select menu. When I want the bare min results I pass bool getMin = true to the sproc, and when I want the complete record I pass bool getMin = false.

This is causing the Entity FrameWork error of "The data reader is incompatible with the specified"

The most relevant portion of the error

{"Message":"An error has occurred.","ExceptionMessage":"The data reader is incompatible with the specified 'CatalogModel.proc_GetFramingSystems_Result'. A member of the type, 'FrameType', does not have a corresponding column in the data reader with the same name.","ExceptionType":"System.Data.EntityCommandExecutionException",

Obviously the error is telling me that when the data reader attempted to set the property 'FrameType' that is was not in the query results.

Now I understand the error, what I am wanting to know is that am I goning to have t split up this sql sproc into two sprocs or is there a work around for this?

My function below

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>();
    };
}

My TSQL below

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
AND c.GlazingMethod = @GlazeMethod
AND c.ID IN(
SELECT cp.ComponentID FROM Catelog.Part p JOIN
            Catelog.ComponentPart cp ON p.ID = cp.PartID
            WHERE p.BrandID = @BrandID
            )
            ORDER BY c.Name
END
ELSE
SELECT c.ID,c.Name,c.Descr
        from Catelog.Component c
WHERE c.MyType ='Frame' 
AND c.FrameType = @FrameType
AND c.GlazingMethod = @GlazeMethod
AND c.ID IN(
SELECT cp.ComponentID FROM Catelog.Part p JOIN
            Catelog.ComponentPart cp ON p.ID = cp.PartID
            WHERE p.BrandID = @BrandID
            )
            ORDER BY c.Name
SET NOCOUNT OFF;
END;

解决方案

To me it seems that both branches of the IF return different data, the first branch returns 9 columns where the second - only three. I believe the EF can't reflect the IFramingSystem from the latter. Specifically, the column FrameType (and 5 other columns) are obviously missing:

 ...
 SELECT c.ID,c.Name,c.Descr    <- where are the remaining columns
    from Catelog.Component c
 ...

这篇关于数据读取器是指定的实体框架不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆