简体   繁体   English

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

[英]SQL to LINQ convertion with full outer join

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)

This is what i have converted so far however i have encounter an error at "&& bookings.bookingId == null" 到目前为止,这是我已转换的内容,但是在“ && bookings.bookingId == null”处遇到错误

The error message is " Operator '&&' cannot be applied to operands of type 'int' and 'bool" 错误消息是“运算符'&&'不能应用于类型为'int'和'bool'的操作数

How do you fix it? 您如何解决?

            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
where bookings.userId = student.userId && bookings.bookingId == null || events.eventId == null || bookings.eventId == null

is being evaluated as 被评估为

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

Because of this, (int)userId && (bool)(bookingId == null) is comparing an int against a bool which violates the language Make sure you use "==" as an evaluation and not the assignment "=". 因此,(int)userId &&(bool)(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)

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

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