SQLite错误:无法删除WhereListIterator`1:没有PK [英] SQLite Error: Cannot delete WhereListIterator`1: it has no PK

查看:67
本文介绍了SQLite错误:无法删除WhereListIterator`1:没有PK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual Studio 2012中使用SQLite/C#从数据库中删除记录.每当我尝试删除记录时,都会出现以下错误:

I'm trying to delete records from a database using SQLite/C# in Visual Studio 2012. Whenever I attempt to delete a record I get the following error:

SQLite错误:无法删除WhereListIterator`1:它没有PK

SQLite Error: Cannot delete WhereListIterator`1: it has no PK

我想使用两种不同的方法删除记录.要么仅使用主键EID删除,要么删除用户提供除EID以外的所有内容的记录.

I am wanting to delete records using two different methods. Either delete using only the EID, which is the primary key, or delete records where the user provides everything but the EID.

if (EID_TextBox.Text != String.Empty) {
    if (Roster_Enrollment.Any(x => x.EID.Equals(Int32.Parse(EID_TextBox.Text)))) {
        App.DBConnection.Delete(Roster_Enrollment.Where(x => x.EID.Equals(Int32.Parse(EID_TextBox.Text))));
        Message_TextBlock.Text = "Enrollment deleted.";
    } else
        Message_TextBlock.Text = "Enrollment not found.";
}
else if (Roster_Enrollment.Any(x => x.CourseNo.Equals(CourseNo_TextBox.Text) && x.SectionNo.Equals(SectionNo_TextBox.Text) && x.Tno.Equals(Tno_TextBox.Text)))
    App.DBConnection.Delete(Roster_Enrollment.Where(x => x.CourseNo.Equals(CourseNo_TextBox.Text) && x.SectionNo.Equals(SectionNo_TextBox.Text) && x.Tno.Equals(Tno_TextBox.Text)));
else
    Message_TextBlock.Text = "Enrollment not found.";

推荐答案

您的类数据模型是否具有Table属性和PrimaryKey属性?

Does your class data model have the Table attribute and PrimaryKey attribute?

[Table("StuffDataModel")]
public class StuffDataModel
{
    [PrimaryKey]
    public int Id { get; set; }

    public byte[] Stuff { get; set; }

}

这篇关于SQLite错误:无法删除WhereListIterator`1:没有PK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆