我可以在VS2013上的windows phone 8.1项目中使用sqlite吗?

时间:2014-04-09 08:32:55

标签: sqlite windows-phone system.data.sqlite

我可以在VS2013的Windows Phone 8.1项目中使用sqlite吗?

我正在使用WP8.1 SDK开发一些Windows Phone 8.1应用程序。 https://dev.windowsphone.com/en-us/downloadsdk 但我根本不能使用sqlite。 我在vs2013扩展上找不到sqilte扩展名。 (VS2013> TOOLS>扩展和更新>在线) 还没有准备好吗?

我在vs2012的W8平板电脑项目中使用了sqilte。 所以我认为我可以用同样的方式。 http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/03/12/using-the-sqlite-database-engine-with-windows-phone-8-apps.aspx

4 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

是的,您可以在Windows Phone App(非SL)8.1项目中使用SQLite。 driver还没有官方版本。更多信息here。我认为还需要一个版本的C ++ / CX包装器,但我并不是100%肯定。那就是here。一旦驱动程序可用,它们应该以与Windows Phone 8当前相同的方式显示在Visual Studio Extensions中。

更新: Using SDK/library references in Universal Windows Apps

答案 2 :(得分:0)

使用LINQ to SQL支持本地数据库。可以使用您的应用程序部署sqlCE参考数据库。

可以在下面找到有关Windows Phone中本地数据库的更多信息

Local Databses

Reference Databases

答案 3 :(得分:0)

@迈克尔

我按照你的指导编写了一些示例代码。 添加System.Data.Linnq.dll引用效果很好,并且构建也很好 但是在运行我的应用程序时发生了InvalidProgramException。 我认为WP8.0和WP8.1彼此之间存在很大差异。

这是异常调用堆栈......

{System.InvalidProgramException: Common Language Runtime detected an invalid program.
at System.Data.Linq.DataContext..ctor(String fileOrConnection)
at KakaoTalk.Tests.LocoChatLogDataContext..ctor(String connectionString)
at KakaoTalk.Tests.SqlCeTestPage.OnNavigatedTo(NavigationEventArgs e)}

这是我的示例代码......

public sealed partial class SqlCeTestPage : Page
{
    public SqlCeTestPage()
    {
        this.InitializeComponent();
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.
    /// This parameter is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var dbCtx = new LocoChatLogDataContext("isostore:/locochatlog.sdf");

        if (dbCtx.DatabaseExists() == true)
        {
            dbCtx.DeleteDatabase();
        }

        dbCtx.CreateDatabase();
    }
}

public class LocoChatLogDataContext : DataContext
{
    // Pass the connection string to the base class.
    public LocoChatLogDataContext(string connectionString) : base(connectionString) { }

    // Specify a single table for the to-do items.
    public Table<LocoChatLog> Items;
}

[Table]
public class LocoChatLog : INotifyPropertyChanged
{
    #region long logId PropertyChanged
    long _logId;
    [Column(IsPrimaryKey = true)]
    public long logId
    {
        get
        {
            return _logId;
        }
        set
        {
            if (_logId != value)
            {
                _logId = value;
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(STR_logId));
                }
            }
        }
    }
    public const string STR_logId = "logId";
    #endregion

    public event PropertyChangedEventHandler PropertyChanged;
}