类型为“方法”的成员在数据读取器中没有具有相同名称的相应列

时间:2017-02-16 01:22:01

标签: c# sql stored-procedures

您好,我收到的错误是

  

数据阅读器与指定的内容不兼容   'TestSearch_Result'。一个成员   type,'Method',数据中没有对应的列   读者同名。

我已经彻底研究过这个问题,尝试了很多解决方案,没有任何效果。任何帮助都会很棒

定义表

PK Id

FK CourseId

FK TypeId

FK MethodId

名称

描述

IsActive

spTestSearch

USE [Project]
GO
/****** Object:  StoredProcedure [dbo].[spTestSearch]    Script Date: 2/15/2017 7:39:51 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  Riley
-- Create date: 2/15/2017
-- Description: Search Attempt 2
-- =============================================
ALTER PROCEDURE [dbo].[spTestSearch] 
-- Add the parameters for the stored procedure here
@Name         NVARCHAR(50),
@CourseIdList           XML,
@TypeIdList             XML,
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT *
    FROM [Definition] ad
         JOIN [Course] c ON ad.CourseId = c.Id
         JOIN [Type] am ON ad.TypeId = am.Id
    WHERE ad.IsActive = 1 AND
    ((ISNULL(@Name, '') = '') OR (ad.Name Like '%'+@Name+'%')) AND 
    ((@CourseIdList IS NULL) OR (ad.CourseId IN
    (       SELECT Id
            FROM dbo.fnIntTableFromXML(@CourseIdList)
     ))) AND
    ((@TypeIdList IS NULL) OR (ad.TypeId IN
    (       SELECT Id
            FROM dbo.fnIntTableFromXML(@TypeIdList)
     )))

END

Db.Model.Context.cs

public virtual ObjectResult<spTestSearch_Result> spTestSearch(string Name, string courseIdList, string TypeIdList)
{
    var NameParameter = Name != null ?
        new ObjectParameter("Name", Name) :
        new ObjectParameter("Name", typeof(string));

    var CourseIdListParameter = courseIdList != null ?
        new ObjectParameter("CourseIdList", courseIdList) :
        new ObjectParameter("CourseIdList", typeof(string));

    var TypeIdListParameter = TypeIdList != null ?
        new ObjectParameter("TypeIdList", TypeIdList) :
        new ObjectParameter("TypeIdList", typeof(string));


    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<spTestSearch_Result>("spTestSearch", NameParameter, CourseIdListParameter, TypeIdListParameter);
}

1 个答案:

答案 0 :(得分:2)

问题可能是因为您正在检索存储过程中所有表的所有字段,并且它不会检索与TestSearch_Result对象的成员匹配的字段,在这种情况下它将是&#39;方法&#39;