具有Employee关系的数据库模式,其属性如下所示,为多值属性指定了类型。
Employee = (ename, ChildrenSet multiset(Children), SkillSet multiset(Skills))
Children = (name, birthday)
Skills = (type, ExmSet setoff(Exams))
Exams = (year, city)
请你帮我。
答案 0 :(得分:0)
定义上述架构,并为每个属性指定适当的类型。
Employees
{
Employee_id, int, PK
Name, nvarchar(50)
}
Childs
{
Child_id, int, PK
Employee_id, int, FK
Name, nvarchar(50)
Birthday, date
}
Skills
{
Skill_id, int, PK
Employee_id, int, FK
Type, nvarchar(50)
}
Exams
{
Exam_id, int, PK
Skill_id, int, FK
Year, int
City, nvarchar(50)
}
查找所有在2000年1月1日或之后出生的孩子的姓名
MyDBEntities db = new MyDBEntities();
var result = from e in db.Employees
join c in db.Childs
on e.Employee_id equals c.Employee_id
where e.Birthday >= new DateTime(2000, 1, 1)
select e;
在“Dayton”城市找到那些参加“键入”技能类型考试的员工
var result = from e in db.Employees
join s in db.Skills
on e.Employee_id equals s.Employee_id
join x in db.Exams
on s.Skill_id equals x.Skill_id
where s.Type.Equals("typing") && x.City.Equals("Dayton")
select e;
列出关系员工
中的所有技能类型var result = from e in db.Employees
join s in db.Skills
on e.Employee_id equals s.Employee_id
select new EmployeeSkill()
{
EmployeeName = e.Name,
SkillType = s.Type
};
底线...... Linq2Sql 规则:)
现在......你只需要将Linq转换为SQL并完成你的作业;)
(你没想到会在这里完成所有工作,对吗?)