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

c#, extension-methods, sqlite, visual-studio-2012

Solution

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; }

}

Problem

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 Error: Cannot delete WhereListIterator`1: it has no PK 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."; ```

Original source