具有完全外连接的SQL到LINQ转换

时间:2016-01-27 06:10:56

标签: c# asp.net linq

SELECT* FROM Event FULL OUTER JOIN Booking ON Event.eventId = Booking.eventId
WHERE(Booking.userId = 3) AND (Booking.bookingId IS NULL) 
OR (Event.eventId IS NULL) 
OR (Booking.eventId IS NULL)

这是我到目前为止所转换的,但我在 "&& bookings.bookingId == null"

错误消息为 "运营商&&'不能应用于' int'类型的操作数和' bool"

你是如何解决的?

            User student = (User)Session["user"];
        var db = new EMS.Models.dbEMSEntities();
        IQueryable<Event> query =  from events in db.Events
                                   join bookings in db.Bookings
                                   on events.eventId equals bookings.eventId
                                   where bookings.userId = student.userId 
                                   && bookings.bookingId == null || events.eventId == null || bookings.eventId == null

2 个答案:

答案 0 :(得分:1)

where bookings.userId = student.userId && bookings.bookingId == null || events.eventId == null || bookings.eventId == null

正在评估为

where bookings.userId = (student.userId && bookings.bookingId == null) || events.eventId == null || bookings.eventId == null

因此,(int)userId&amp;&amp; (bool)(bookingId == null)将int与违反该语言的bool进行比较 确保使用“==”作为评估而不是作业“=”。

答案 1 :(得分:0)

   User student = (User)Session["user"];
        var db = new EMS.Models.dbEMSEntities();
        IQueryable<Event> query =  from events in db.Events
                                   join bookings in db.Bookings
                                   on events.eventId equals bookings.eventId
                                   where (bookings.userId == student.userId)
                                   && (bookings.bookingId == null) || (events.eventId == null) || (bookings.eventId == null)