我制作了选择有条件的数据的存储过程,但问题是:-
当RequiredIDID = 2(选择带有连接表中的一些数据,如果不是,我不在else语句中选择它)并且映射到linq函数后出现此问题
如果我将 requirdID = 2 传递给函数,则不会出现问题,因为 proc 中的第一个选择已执行,但如果我传递其他 requirdID(例如 = 3),则会出现此消息
数据读取器与指定的“RealEstateCenterModel.SearchForRealState_Reader”不兼容。类型的成员“FloorTypeCategory”在数据读取器中没有同名的对应列。
USE [RealEstateCenter]
GO
/****** Object: StoredProcedure [dbo].[TestOptionalParameter] Script Date: 08/23/2012 07:29:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[TestOptionalParameter]
@RequiredIDID int =NULL
as
if @RequiredIDID=2
begin
SELECT FloorSpace.SpaceFrom, RealEstateCategoryDetails.RequiredCategoryTypeName, FloorType.FloorTypeCategory, FloorType.FloorNotes,
RealEstateTypes.RequiedType
FROM PersonalRealStateDetails INNER JOIN
FloorSpace ON PersonalRealStateDetails.FloorSpaceID = FloorSpace.FloorSpaceID INNER JOIN
RealEstateCategoryDetails ON PersonalRealStateDetails.RequiredCategoryTypeID = RealEstateCategoryDetails.RequiredCategoryTypeID INNER JOIN
FloorType ON PersonalRealStateDetails.FloorTypeID = FloorType.FloorTypeID INNER JOIN
RealEstateTypes ON RealEstateCategoryDetails.RequiredID = RealEstateTypes.RequiredID
end
else
begin
SELECT FloorSpace.SpaceFrom, RealEstateCategoryDetails.RequiredCategoryTypeName, RealEstateTypes.RequiedType
FROM PersonalRealStateDetails INNER JOIN
FloorSpace ON PersonalRealStateDetails.FloorSpaceID = FloorSpace.FloorSpaceID INNER JOIN
RealEstateCategoryDetails ON PersonalRealStateDetails.RequiredCategoryTypeID = RealEstateCategoryDetails.RequiredCategoryTypeID INNER JOIN
RealEstateTypes ON RealEstateCategoryDetails.RequiredID = RealEstateTypes.RequiredID
end
我该如何解决这个问题?