<>的成员type,'ClassID',数据中没有相应的列&gt;读者同名

时间:2014-12-08 07:03:11

标签: c# sql stored-procedures sql-server-2012 subquery

我已经创建了这个存储过程,这可能有点长但是它可以工作。但是,我使用实体框架来完成这个项目。但是当它运行时它给了我这个错误:

  

未处理的类型异常   &#39; System.Data.EntityCommandExecutionException&#39;发生在   System.Data.Entity.dll

     

其他信息:数据阅读器与。不兼容   指定&#39; SchoolsModel.TeacherClassesSorting_Result&#39;。一个成员   类型,&#39; ClassID&#39;,在数据中没有对应的列   读者同名。

这是我在SQL Server中创建的SP:

ALTER PROCEDURE [dbo].[TeacherClassesSorting] 
@ID int,
@sub int,
@frm int,
@trm int,
@yr nvarchar(15)
AS 
BEGIN
--SORTING BY ID ONLY
IF @trm IS NULL and @frm IS NULL and @sub IS NULL AND @yr IS NULL
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID 
ORDER BY AcademicYear DESC, c.FormID DESC
END

--Sorting by Year
ELSE IF @yr IS NOT NULL
BEGIN
--SORTING BY ID AND YEAR
IF @trm >0 and @frm IS NULL and @sub IS NULL
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID and c.AcademicYear = @yr and c.TermID = @trm
ORDER BY AcademicYear DESC, Form DESC
END

ELSE
IF @trm >0 and @frm >0 and @sub IS NULL
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID and c.AcademicYear = @yr and c.TermID = @trm AND C.FormID = @frm
ORDER BY AcademicYear DESC, Form DESC
END

ELSE
IF @trm >0 and @frm IS NULL and @sub >0
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID and c.AcademicYear = @yr and c.TermID = @trm AND C.SubjectCode = @sub
ORDER BY AcademicYear DESC, Form DESC
END


ELSE
IF @trm IS NULL and @frm IS NULL and @sub >0
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID and c.AcademicYear = @yr AND C.SubjectCode = @sub
ORDER BY AcademicYear DESC, Form DESC
END

ELSE
IF @trm IS NULL and @frm >0 and @sub >0
BEGIN
select c.ClassID as ID,sub.SubjectName as Subject, f.FormName as Form, trm.TermName as AcademicTerm , c.AcademicYear as AcademicYear
from Teachers as t inner join Classes as c on t.TeacherID = c.TeacherID 
              inner join Subjects as sub on sub.SubjectCode = c.SubjectCode
              inner join Terms as trm on trm.TermID = c.TermID
              inner join SchoolForms as f on f.FormID = c.FormID 
where         t.UserID = @ID and c.AcademicYear = @yr AND C.SubjectCode = @sub AND C.FormID = @frm
ORDER BY AcademicYear DESC, Form DESC
END

我是编程新手,所以请耐心等待,我并不完美。谁能帮我。谢谢!

0 个答案:

没有答案