2012-11-29 34 views
1

我有三个表创建为这样:有一个多对多的LINQ遇到问题选择

enter image description here

我想什么做的就是选择其中一个AdministratorAttendee记录存在一个给定的AttendeeId与会者和AdministratorId。

我已经试过是这样的:

var result = (from a in dc.Attendees 
       from aa in dc.AdministratorAttendees 
       where aa.AdministratorId == this.CurrentAdminId && a.AttendeeId == _attendee.AttendeeId 
       select a); 

但是,尽管与会者,管理员和AdministratorAttendee记录存在指定ID的事实,它返回任何结果。

什么是正确的linq查询使用?

感谢

+0

'this'指的是什么?目前的对象是什么? – SAJ14SAJ

+0

当前页面类。基本上CurrentAdminId和_attendee.AttendeeId是两个参数 – alimac83

+0

什么是id字段的类型? –

回答

1

你尝试这种方式?

var result = (from a in dc.Attendees 
        join aa in dc.AdministratorAttendees 
        on new { aa.AdministratorId, a.AttendeeId } equals 
        new { this.CurrentAdminId, _attendee.AttendeeId } 
        select a); 
+0

您不能使用'equals'两次 –

+0

对不起,请参阅编辑后的版本 –