我对某些事感到困惑。我理解ORM在做什么,我理解EF是什么。我朦胧的是我不想使用专门的构造来获取数据的部分。我想使用SQL。如果我在SQL中创建一个复杂的查询,很多子查询等等,我是正确的,如果我想能够像属性一样处理数据,我必须创建一个特殊的自定义类,仅用于该查询。
我想到这样的场景。有人需要信息。它需要一个复杂的查询,从5个不同的表中返回20列。我需要创建一个包含这些列的类,然后编写查询。这是对的吗?
我正在看这个教程,
using System;
using System.Collections.Generic;
namespace ContosoUniversity.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
}
如果这是Moodle或其他LMS或学生信息系统,该怎么办?它们变得复杂,并且需要来自多个表格的大量连接和数据。
这会重复吗:
public virtual ICollection<Enrollment> Enrollments { get; set; }
public virtual ICollection<Schedule> Schedules{ get; set; }
public virtual ICollection<SubjectContext> SubjectContexts{ get; set; }
public virtual ICollection<Grade> Grades{ get; set; }
public virtual ICollection<Instructor> Instructors{ get; set; }
例如,请考虑以下问题:
SELECT user.firstname, user.lastname, user.email, user.country, cc.name AS 'course category name', c.fullname, q.name, question.content AS 'Question', choice.content AS 'Question option', choicerank.rank AS 'Choice value'
FROM mdl_course_categories AS cc
INNER JOIN mdl_course AS c ON c.category = cc.id
INNER JOIN mdl_questionnaire AS q ON q.course = c.id
INNER JOIN mdl_questionnaire_question AS question ON question.survey_id = q.id
INNER JOIN mdl_questionnaire_quest_choice AS choice ON choice.question_id = question.id
INNER JOIN mdl_questionnaire_response_rank AS choicerank ON choicerank.choice_id = choice.id
JOIN mdl_context AS ctx ON c.id = ctx.instanceid
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
JOIN mdl_user AS user ON user.id = ra.userid
ORDER BY user.firstname
这是否需要自定义类?
如果我做了.toList(String)
的事情,是否会破坏使用框架开始的目的?
答案 0 :(得分:1)