如何将三个或更多列表组合到一个列表中。 [英] How to combine three or more lists into one list.

查看:116
本文介绍了如何将三个或更多列表组合到一个列表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends,

I am having a requirement like below.

class Final
{
public string EmployeName{get;set;}
public string Gender{get;set;}
public string DepartId{get;set;}
public string DepartName{get;set;}
public string SalaryId{get;set;}
public string Salary{get;set;}
}

class Emp
{
public string EmployeName{get;set;}
public string Gender{get;set;}

}

class Department
{
public string DepartId{get;set;}
public string DepartName{get;set;}
}
class Salary
{
public string SalaryId{get;set;}
public string Salary{get;set;}
}
Having the list of Final, Emp, Department and Salary like below

lstFinal, lstEmp,lstDepartment,lstSalary


Want a linq query with  final list to be a combination of lstEmp, lstDepartment,lstSalary

Like below table.
Please kindly help me out.

------------------|------|--------|----------|--------|------|-
|-EmployeName-----|Gender|DepartId|DepartName|SalaryId|Salary|
|                                                            |
|                                                            |

What I have tried:

var result= from e Emp
  join d in dept on e.EmployeName equals e.EmployeName
 join g in gend on g.Gender equals g.Gender
select new Final(){EmployeName=e.EmployeName, Gender=e.Gender, DepartId=d.DepartId, DepartName=d.DepartName,SalaryId=s.SalaryId,Salary=s.Salary}

推荐答案

如果我理解正确并且您从数据库获取信息,在SQL存储过程中执行此操作会更好。 SQL会让我更快,更容易使用,而不是Kluge。使您的类成为最终的对象结构,并从sp调用中填充它。



记住即使使用SQL,取决于每个表中有多少连接/内部连接和记录,您最好使用emp数据构建临时表并清空其他数据的占位符,然后更新其关联表中的其他字段
If I understand this correctly and your getting the info from a Database, You will be MUCH better off to do this inside a SQL Stored Procedure. SQL will me much faster, easier to work with and less of a Kluge. make your class your final object structure and populate it from a sp call.

And remember even with SQL depending on how many joins / inner joins and records in each table you may be better off to build a temp table using the emp data and empty placeholders for the other data and then update the other fields from their associated tables


这篇关于如何将三个或更多列表组合到一个列表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆