Reputation: 4503
Hello I am getting an error on that reads
The data reader is incompatible with the specified 'TestSearch_Result'. A member of the type, 'Method', does not have a corresponding column in the data reader with the same name.
I have thoroughly researched the issue, tried numerous solutions and nothing worked. Any assistance would be great
Definition Table
PK Id
FK CourseId
FK TypeId
FK MethodId
Name
Description
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);
}
Upvotes: 0
Views: 924
Reputation: 146
The problem may be because you are retrieving all fields of all tables in your stored procedure and it doesn't retrieve a field that matches with a member of the TestSearch_Result object, in this case it would be 'Method'.
Upvotes: 2