class Program
{
static void Main(string[] args)
{
List<Project> plist = new List<Project>() {
new Project(){ ID = 1,PName = "项目1",MID = 1},
new Project(){ ID = 2,PName = "项目2",MID = 2},
new Project(){ ID = 3,PName = "项目3",MID = 3},
new Project(){ ID = 4,PName = "项目4",MID = 1},
new Project(){ ID = 5,PName = "项目5",MID = 2},
new Project(){ ID = 6,PName = "项目6",MID = 3},
};
List<Users> ulist = new List<Users>() {
new Users(){ ID = 1,UName = "员工1"},
new Users(){ ID = 2,UName = "员工2"},
new Users(){ ID = 3,UName = "员工3"},
new Users(){ ID = 4,UName = "员工4"},
new Users(){ ID = 5,UName = "张三"},
new Users(){ ID = 6,UName = "员工6"},
new Users(){ ID = 7,UName = "员工7"},
new Users(){ ID = 8,UName = "员工8"},
};
List<Manager> mlist = new List<Manager>() {
new Manager(){ ID = 1,MName = "经理1"},
new Manager(){ ID = 2,MName = "经理2"},
new Manager(){ ID = 3,MName = "经理3"},
};
List<Performance> list = new List<Performance>() {
new Performance(){ PID = 1,UID = 1,Score = 89},
new Performance(){ PID = 1,UID = 2,Score = 90},
new Performance(){ PID = 2,UID = 3,Score = 99},
new Performance(){ PID = 3,UID = 4,Score = 100},
new Performance(){ PID = 4,UID = 5,Score = 98},
new Performance(){ PID = 5,UID = 6,Score = 89},
new Performance(){ PID = 5,UID = 7,Score = 97},
new Performance(){ PID = 6,UID = 8,Score = 68},
};
var a = from i in list
group i by i.PID
into s
select new
{
Key = s.Key,
Count = s.Sum(p => p.Score)
};
Console.WriteLine("========================");
foreach (var item in a)
{
Console.WriteLine(item.Key+","+item.Count);
}
Console.WriteLine("========================");
var aa = from i in list
group i by i.PID
into s
select new
{
Key = s.Key,
Count = s.Max(p => p.Score)
};
Console.WriteLine("========================");
foreach (var item in aa)
{
Console.WriteLine(item.Key + "," + item.Count);
}
Console.WriteLine("========================");
var xx = from jx in list
join emp in plist on jx.PID equals emp.ID
join user in ulist on jx.UID equals user.ID
join jl in mlist on emp.MID equals jl.ID
select new
{
XiangMu = emp.PName,
JinglI = jl.MName,
UserName = user.UName,
JiXiao = jx.Score
};
var groups = from x in xx
group x by x.XiangMu;
foreach (var item in groups)
{
Console.WriteLine(item.Key+"=================================");
foreach (var i in item)
{
Console.WriteLine(i.XiangMu + "\t" + i.JinglI + "\t" + i.UserName + "\t" + i.JiXiao);
}
}
var max = xx.Max(p => p.JiXiao);
var min = xx.Min(p => p.JiXiao);
var avg = xx.Average(p => p.JiXiao);
Console.WriteLine(max+","+min+","+avg);
Console.ReadLine();
}
class Project
{
public int ID { get; set; }
public string PName { get; set; }
public int MID { get; set; }
}
class Users
{
public int ID { get; set; }
public string UName { get; set; }
}
class Manager
{
public int ID { get; set; }
public string MName { get; set; }
}
class Performance
{
public int UID { get; set; }
public int PID { get; set; }
public int Score { get; set; }
}
}