【发布时间】:2021-02-14 09:05:34
【问题描述】:
如何检查数据库中是否存在条目?调试显示result返回null。
TimeSlots 一个集合。我不确定我是否正确地做到了。
这是我的上下文:
var result = await context.Bookings
.SingleOrDefaultAsync(b =>
b.BookDate == booking.BookDate
&& b.TimeSlots == booking.TimeSlots
&& b.RoomId == booking.RoomId);
public class Booking
{
public int Id { get; set; }
[Required]
public DateTime BookDate { get; set; }
[Required]
public int RoomId { get; set; }
public Room Room { get; set; }
[Required]
public ICollection<BookingTimeSlot> TimeSlots { get; set; }
[Required]
public ICollection<BookingModule> Modules { get; set; }
public Booking()
{
TimeSlots = new Collection<BookingTimeSlot>();
Modules = new Collection<BookingModule>();
}
}
public class BookingTimeSlot
{
public int BookingId { get; set; }
public int TimeSlotId { get; set; }
public Booking Booking { get; set; }
public TimeSlot TimeSlot { get; set; }
}
这是我要输入的内容:
{
"RoomId": 1,
"BookDate": "2020-10-27",
"TimeSlots": [1, 3],
"Modules": [1]
}
【问题讨论】:
标签: c# asp.net asp.net-core asp.net-web-api asp.net-core-webapi