这让我感到困惑,我在以下 LINQ 中的连接中出现标题错误:
var r = (from k in location.tblKeyAccountInfoes
join l in location.tblLocations
on new { k.MemberID, k.LocationID } equals
new {l.MemberId, l.LocationId }
where k.MemberID == memberid && k.UserName == username
select l.LocationName);
return r.ToString();
但是,MemberId 和 LocationId 的类型相同,所以我不确定我做错了什么。
感谢收到的任何指示。
最佳答案
MemberID 和 LocationID 的类型可以相同,但它们也必须具有相同的名称。
在您的示例中,其中一个具有 ID(大写 D),另一个具有 Id(小写 d)。这足以使匿名类型成为独立的类型。
您可以通过明确指定名称来解决此问题,例如:
join l in location.tblLocations
on new { k.MemberID, k.LocationID } equals
new { MemberID = l.MemberId, LocationID = l.LocationId }
关于c# - 当类型相同时,连接子句中的一个表达式的类型不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3769098/