classProgram{staticvoidMain(string[] args){
List<Project> plist =newList<Project>(){newProject(){ ID =1,PName ="项目1",MID =1},newProject(){ ID =2,PName ="项目2",MID =2},newProject(){ ID =3,PName ="项目3",MID =3},newProject(){ ID =4,PName ="项目4",MID =1},newProject(){ ID =5,PName ="项目5",MID =2},newProject(){ ID =6,PName ="项目6",MID =3},};
List<Users> ulist =newList<Users>(){newUsers(){ ID =1,UName ="员工1"},newUsers(){ ID =2,UName ="员工2"},newUsers(){ ID =3,UName ="员工3"},newUsers(){ ID =4,UName ="员工4"},newUsers(){ ID =5,UName ="张三"},newUsers(){ ID =6,UName ="员工6"},newUsers(){ ID =7,UName ="员工7"},newUsers(){ ID =8,UName ="员工8"},};
List<Manager> mlist =newList<Manager>(){newManager(){ ID =1,MName ="经理1"},newManager(){ ID =2,MName ="经理2"},newManager(){ ID =3,MName ="经理3"},};
List<Performance> list =newList<Performance>(){newPerformance(){ PID =1,UID =1,Score =89},newPerformance(){ PID =1,UID =2,Score =90},newPerformance(){ PID =2,UID =3,Score =99},newPerformance(){ PID =3,UID =4,Score =100},newPerformance(){ PID =4,UID =5,Score =98},newPerformance(){ PID =5,UID =6,Score =89},newPerformance(){ PID =5,UID =7,Score =97},newPerformance(){ PID =6,UID =8,Score =68},};//求不同成员的绩效成绩和var a =from i in list
group i by i.PIDinto s
selectnew{
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.PIDinto s
selectnew{
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.IDjoin user in ulist on jx.UID equals user.IDjoin jl in mlist on emp.MID equals jl.IDselectnew{
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 +" "+ i.JinglI +" "+ i.UserName +" "+ 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();}//项目classProject{publicint ID {get;set;}publicstring PName {get;set;}publicint MID {get;set;}}//员工classUsers{publicint ID {get;set;}publicstring UName {get;set;}}//经理classManager{publicint ID {get;set;}publicstring MName {get;set;}}//绩效classPerformance{publicint UID {get;set;}publicint PID {get;set;}publicint Score {get;set;}}}