SQLite 考勤日期记录 table 结构 |删除哪里 |首要的关键

SQLite attendance date records table structure | delete where | primary key

我有一个使用 SQLite 数据库构建的 Xamarin.Forms 应用程序。我想记录学生的出勤情况。我想出席 table 只有 2 列:

public class Attendance
{
    public DateTime AttendanceDate { get; set; }
    public int StudentID { get; set; }
}

我 运行 遇到的问题是删除方法。 DeleteAsync 方法只需要一个主键,如下所示:

db.DeleteAsync<Attendance>(primaryKey)

但是我发现 SQLite 不支持连接主键。所以当用户要删除考勤记录时,我没有主键可以传入删除记录。我能想到的唯一解决方法是:

有没有办法通过 DeleteAsync 方法传入 WHERE 子句?像这样:

db.DeleteAsync<Attendance>(
    where (date == dateVariable && studentID == idVariable) )

或者我是否需要更改 table 结构以添加一个自动递增的主键?

同意 Jason 的观点,您可以通过 QueryAsync

删除此 Attendance
Database.QueryAsync<Attendance>("DELETE FROM Attendance WHERE AttendanceDate =? AND StudentID =? ",attendance.AttendanceDate ,attendance.StudentID);

或者如果你能得到Attendance模型。可以按Attendance型号删除。

var attendance=new Attendance() { AttendanceDate= DateTime.Now,StudentID=1 };
Database.DeleteAsync<Attendance>(attendance);