您如何在LINQ中编码交叉联接? [英] How do you code a cross join in LINQ?
本文介绍了您如何在LINQ中编码交叉联接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有一个过程返回两个不同的对象列表.两个列表中的对象属于同一类型.我需要将两个列表交叉连接在一起以形成一个集成列表.如果是SQL,则可能是这样的:
I have a process in my application that returns two different lists of objects. The objects in both lists are of the same type. I need to cross join the two lists together to form one integrated list. If it were SQL, it'd be something like this:
SELECT A.KEY, A.DATA AS DATA1, B.DATA AS DATA2
FROM TABLE1 AS A
CROSS JOIN TABLE2
这是纯LINQ,因为数据是在实际的通用List <<>集合中返回的.
This is pure LINQ as the data is returned in actual generic List<> collections.
此操作的LINQ语法是什么?
What is the LINQ syntax for this operation?
托尼
推荐答案
var res = from t1 in table1
from t2 in table2
select new
{
KEY = t1.KEY,
DATA1 = t1.DATA,
DATA2 = t2.DATA,
};
这篇关于您如何在LINQ中编码交叉联接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文