C# 当类型相同时,join子句中某个表达式的类型不正确
这让我很困惑,我在以下LINQ中的连接上出现了标题错误:C# 当类型相同时,join子句中某个表达式的类型不正确,c#,linq,C#,Linq,这让我很困惑,我在以下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 }
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 }
啊对-嘘!!!很好的更新和做的把戏-干杯Timwi,最赞赏和良好的解释以及。