我正在尝试运行自定义查询,我正在使用Entity框架,我试过这个
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
获取结果?
答案 0 :(得分:4)
没有。 EF的ExecuteStoreQuery
要求数据类型(类)具有与您的查询结果集中的列相同的属性。如果要在不为其结果集创建特殊类型的情况下执行查询,则必须直接使用ADO.NET和SqlDataReader
。