linq 多表连接测试
static
void Main(
string[] args)
{
var c1 = new List<KeyValuePair< int, int>>() { new KeyValuePair< int, int>(1, 1), new KeyValuePair< int, int>(2, 2), new KeyValuePair< int, int>(3, 3) };
var c2 = new List<KeyValuePair< int, float>>() { new KeyValuePair< int, float>(0, 0f), new KeyValuePair< int, float>(1, 1.1f), new KeyValuePair< int, float>(2, 2.2f) };
var c3 = new List<KeyValuePair< int, string>>() { new KeyValuePair< int, string>(2, "2"), new KeyValuePair< int, string>(3, "3"), new KeyValuePair< int, string>(4, "4") };
var res = from x in c1
join y in c2 on x.Key equals y.Key
join z in c3 on y.Key equals z.Key
select new { o = x.Value, p = y.Value, q = z.Value };
var _res = res.ToArray();
}
{
var c1 = new List<KeyValuePair< int, int>>() { new KeyValuePair< int, int>(1, 1), new KeyValuePair< int, int>(2, 2), new KeyValuePair< int, int>(3, 3) };
var c2 = new List<KeyValuePair< int, float>>() { new KeyValuePair< int, float>(0, 0f), new KeyValuePair< int, float>(1, 1.1f), new KeyValuePair< int, float>(2, 2.2f) };
var c3 = new List<KeyValuePair< int, string>>() { new KeyValuePair< int, string>(2, "2"), new KeyValuePair< int, string>(3, "3"), new KeyValuePair< int, string>(4, "4") };
var res = from x in c1
join y in c2 on x.Key equals y.Key
join z in c3 on y.Key equals z.Key
select new { o = x.Value, p = y.Value, q = z.Value };
var _res = res.ToArray();
}
特点:
1、多集合连接,建立在可判定相等键值基础上
2、不断连接,缩小交集范围
转载于:https://blog.51cto.com/szgamer/213848