【问题标题】:A member of the type, 'Method', does not have a corresponding column in the data reader with the same name类型的成员“方法”在数据读取器中没有同名的对应列
【发布时间】:2017-02-16 01:22:01
【问题描述】:

您好,我收到一个错误提示

数据读取器与指定的不兼容 'TestSearch_Result'。的成员 类型“方法”在数据中没有对应的列 同名阅读器。

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

定义表

PK 标识

FK 课程编号

FK 类型标识

FK 方法标识符

名字

说明

活跃

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

【问题讨论】:

  • 您使用的是哪个 dbms? (该代码是特定于产品的。)

标签: c# sql stored-procedures


【解决方案1】:

问题可能是因为您正在检索存储过程中所有表的所有字段,并且它没有检索到与 TestSearch_Result 对象的成员匹配的字段,在这种情况下它将是“方法”。

【讨论】:

  • 你说得对,这就是问题所在!现在我知道将“ Select * ”用于存储过程是不合适的。请给我的帖子点赞。你的洞察力太棒了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-04
相关资源
最近更新 更多