3

我正在尝试运行自定义查询并且我正在使用实体框架,我尝试了这个

string query = @"SELECT dm.DistrictName,sm.SchoolName,u.UserId,u.FirstName,u.LastName, sa.StudentId, sa.ReadingLevel
                 FROM  studentassessment sa
                 INNER JOIN assessmentmaster am ON sa.AssessmentId = am.AssessmentId
                 INNER JOIN studentclass sc ON sa.StudentId = sc.StudentId
                 INNER JOIN USER u ON sc.TeacherId = u.UserId
                 INNER JOIN schoolmaster sm ON u.SchoolCode = sm.SchoolCode
                 INNER JOIN  districtmaster dm ON sm.DistrictId = dm.DistrictId
                 WHERE u.RoleId = 5 && sa.GradeId = " + objParam.Grade + " && sa.AssessmentPeriodId = " + x.AssessmentPeriodId + " && dm.DistrictId = " + districtCode + " && am.DRAType = '" + objParam.LanguageType + "' && am.AssessmentTypeId = 1";



var dt = db.ExecuteStoreQuery<List<object>>(query).FirstOrDefault();

但是没有成功。

有没有办法ExecuteStoreQuery从未映射到任何对象类型的结构中获取结果?

4

1 回答 1

4

不。EFExecuteStoreQuery要求数据类型(类)具有与您的查询结果集中的列同名的属性。如果要在不为其结果集创建特殊类型的情况下执行查询,则必须SqlDataReader直接使用 ADO.NET。

于 2013-01-29T15:57:52.100 回答