Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Phone 8.1 SQLite删除错误:无主键_C#_Sqlite_Windows Phone 8.1_Primary Key - Fatal编程技术网

C# Windows Phone 8.1 SQLite删除错误:无主键

C# Windows Phone 8.1 SQLite删除错误:无主键,c#,sqlite,windows-phone-8.1,primary-key,C#,Sqlite,Windows Phone 8.1,Primary Key,我正在尝试使用SQLite for Windows Phone删除sql数据库中的一行。这是我的dbHelper类: public void DeleteContact(int Id) { using (var dbConn = new SQLiteConnection("models.db")) { var existingconact = dbConn.Query<item>("select * from item

我正在尝试使用SQLite for Windows Phone删除sql数据库中的一行。这是我的dbHelper类:

public void DeleteContact(int Id)
    {
        using (var dbConn = new SQLiteConnection("models.db"))
        {

            var existingconact = dbConn.Query<item>("select * from item where Id =" + Id).FirstOrDefault();
            if (existingconact != null)
            {
                dbConn.RunInTransaction(() =>
                {
                    dbConn.Delete(existingconact);
                });
            }
        }
    }
但每次我点击应用程序中的“删除”按钮时,都会弹出以下错误:

无法删除项目:它没有主键

我尝试向我的表的Id列添加主键和自动递增,因为我找到的中的家伙有以下图片:

你知道如何解决这个问题吗

编辑:我的模型类如下所示:

public class item
{
    public string Name { get; set; }
    public string Hersteller { get; set; }
    public double EWD { get; set; }
    public string TTiefe { get; set; }
    public string TAbstand1 { get; set; }
    public string TAbstand2 { get; set; }
    public string HTiefe { get; set; }
    public string HAbstand1 { get; set; }
    public string HAbstand2 { get; set; }
    public int Id { get; set; }
    public int SenderNr { get; set; }
    public bool Segler { get; set; }
    public double Spannweite { get; set;}
    public double Gewicht { get; set; }
    public double Flaeche { get; set; }
    public double FBelastung { get; set; }


    public item()
    {
        //Constructor
    }

    public item(string name, int ID, string hersteller, double ewd, string tTiefe, string tAbstand1, string tAbstand2, string hTiefe, string hAbstand1, string hAbstand2, int senderNr, bool segler, double spannweite, double gewicht, double flaeche, double fBelastung)
    {
        Name = name;
        Hersteller = hersteller;
        Id = ID;
        EWD = ewd;
        TTiefe = tTiefe;
        TAbstand1 = tAbstand1;
        TAbstand2 = tAbstand2;
        HTiefe = hTiefe;
        HAbstand1 = hAbstand1;
        HAbstand2 = hAbstand2;
        SenderNr = senderNr;
        Segler = segler;
        Spannweite = spannweite;
        Gewicht = gewicht;
        Flaeche = flaeche;
        FBelastung = fBelastung;

    }
}

您是如何定义模型类的?您需要使用
[PrimaryKey,AutoIncrement]
属性标记
Id
属性。谢谢您的回答,但是在哪里?在DeleteContact方法中,还是在sql表中?非常感谢,它起了作用:)我必须将它添加到item类中。你真的帮了我很多忙你是如何定义你的模型类的?你需要用
[PrimaryKey,AutoIncrement]
属性标记你的
Id
属性。谢谢你的回答,但是在哪里?在DeleteContact方法中,还是在sql表中?非常感谢,它起了作用:)我必须将它添加到item类中。你真的帮了我很多
public class item
{
    public string Name { get; set; }
    public string Hersteller { get; set; }
    public double EWD { get; set; }
    public string TTiefe { get; set; }
    public string TAbstand1 { get; set; }
    public string TAbstand2 { get; set; }
    public string HTiefe { get; set; }
    public string HAbstand1 { get; set; }
    public string HAbstand2 { get; set; }
    public int Id { get; set; }
    public int SenderNr { get; set; }
    public bool Segler { get; set; }
    public double Spannweite { get; set;}
    public double Gewicht { get; set; }
    public double Flaeche { get; set; }
    public double FBelastung { get; set; }


    public item()
    {
        //Constructor
    }

    public item(string name, int ID, string hersteller, double ewd, string tTiefe, string tAbstand1, string tAbstand2, string hTiefe, string hAbstand1, string hAbstand2, int senderNr, bool segler, double spannweite, double gewicht, double flaeche, double fBelastung)
    {
        Name = name;
        Hersteller = hersteller;
        Id = ID;
        EWD = ewd;
        TTiefe = tTiefe;
        TAbstand1 = tAbstand1;
        TAbstand2 = tAbstand2;
        HTiefe = hTiefe;
        HAbstand1 = hAbstand1;
        HAbstand2 = hAbstand2;
        SenderNr = senderNr;
        Segler = segler;
        Spannweite = spannweite;
        Gewicht = gewicht;
        Flaeche = flaeche;
        FBelastung = fBelastung;

    }
}