简体   繁体   English

LINQ中有超过2个表JOIN,作用域问题

[英]More than 2 tables JOIN in LINQ, scope issue

I am trying to join 3 table in LINQ. 我正在尝试加入LINQ中的3表。

var fromCities = from c in cityRepository.Cities
                             join r in routeRepository.Routes on c.Id equals r.FromCityId
                             join cr in rentDetailRepository.CarRentDetails on cr.CityId equals c.Id
                             select c;

I am getting that cr and c do not exist in the second join statement? 我在第二个join语句中发现cr和c不存在? Could somebody help? 有人可以帮忙吗?

Change the order in the last join: 更改最后一个联接中的顺序:

...
join cr in rentDetailRepository.CarRentDetails on c.Id equals cr.CityId 

join clause (C# Reference) join子句(C#参考)

A join clause performs an equijoin. 连接子句执行等价连接。 In other words, you can only base matches on the equality of two keys. 换句话说,您只能基于两个键的相等性进行匹配。 Other types of comparisons such as "greater than" or "not equals" are not supported. 不支持其他类型的比较,例如“大于”或“不等于”。 To make clear that all joins are equijoins, the join clause uses the equals keyword instead of the == operator. 为了明确所有联接都是等联接,join子句使用equals关键字而不是==运算符。 The equals keyword can only be used in a join clause and it differs from the == operator in one important way. equals关键字只能在join子句中使用,它在一个重要方面与==运算符不同。 With equals, the left key consumes the outer source sequence, and the right key consumes the inner source. 使用equals时,左键消耗外部源序列,而右键消耗内部源序列。 The outer source is only in scope on the left side of equals and the inner source sequence is only in scope on the right side. 外源仅在equals的左侧范围内,而内源序列仅在equals的右侧范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM