具有完全外部联接的 SQL 到 LINQ 转换
本文关键字:SQL LINQ 转换 外部 | 更新日期: 2023-09-27 18:31:59
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
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 && (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)