检查在SQLite PCL UWP中是否存在行

本文关键字:是否 存在 UWP SQLite PCL 检查 | 更新日期: 2023-09-27 18:14:01

我试图检查一行是否存在于sqlite数据库中,它是一个uwp。我发现所有的例子都不适合SQLite。Net-PCL,不知道为什么他们不同…如果有人有sqlpcl命令的链接,请随时添加:)。

现在我的代码和我所尝试的:

    private void AdMovieID()
    {
        var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MovieID.sqlite");
        SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath);
//I have the code down below but that dosent work well at all.. :) 
       /* var movies = conn.Table<MovieID>().ToList();
        foreach (var id in movies)
        {
          if (id.ID != App.Moviess.Filmerna[index].id.ToString())
            {
                conn.Insert(new MovieID { ID = App.Moviess.Filmerna[index].id.ToString() });
            }

        }*/
    }

数据库使用的类:

public class MovieID
    {
        public string ID { get; set; }
    }

检查在SQLite PCL UWP中是否存在行

使用LINQ:

MovieID movie = (from p in db.Table<MovieID>() 
            where p.ID == searchId 
            select p).FirstOrDefault();
if(movie !=null)
{
//movie exists
}
else
{
  //movie do not exists
}