我正在使用asp.NET MVC。我正试图找到员工的薪资等级,就像我们在甲骨文12c中使用scott模式所发现的那样。我已经创建了4个模型EMP,部门,奖金和SalGrade (与oracle12c中的schema相同)。在Oracle-12c中查找分数的查询如下所示。
SELECT s.grade, count(*), max(sal)
FROM EMP e, SalGrade s
WHERE e.sal BETWEEN s.LoSal AND s.HiSal
GROUP BY s.grade;我只需要将上述给定的查询转换为ASP.NET MVC LINQ查询.
我创造的模型都是随处可见的。
部门模型:
public class Department{
[Key]
public int Deptno { get; set; }
public string Dname { get; set; }
public string Loc { get; set; }}电磁脉冲模型:
public class Employee
{
[Key]
public int Empno { get; set; }
public string Ename { get; set; }
public string Job { get; set; }
public int Mgr { get; set; }
public DateTime Hiredate { get; set; }
public int Sal { get; set; }
public int Comm { get; set; }
public int Deptno { get; set; }
public Department Department { get; set; }
}SalGrade模型
public class Salgrade
{
[Key]
public int Grade { get; set; }
public int LoSal { get; set; }
public int HiSal { get; set; }
}发布于 2020-03-20 14:44:56
在控制器类方法中,可能有如下代码:
using(var db = new DepartmentEntities()){
var query = from db.Employee, db.Salgrade
where db.Employee.Sal between db.Salgrade.LoSal and db.Salgrade.HiSal
group by db.Salgrade.Grade
select new { db.Salgrade.Grade, count(*), max(db.Employee.Sal) };
// Use query results in a foreach loop or whatever...
} https://stackoverflow.com/questions/60773336
复制相似问题