我正在构建一个Windows 8应用程序,现在我想在这个应用程序中使用SQLite.我SQLite for Windows Runtime通过Visual Studio 2013扩展管理器安装,并sqlite-net通过NuGet 添加到我的项目中.
我正在尝试在app.xaml.cs中创建一个数据库OnLaunched,但是在运行项目时遇到了这个异常:
无法加载DLL的'sqlite3':找不到指定的模块.(来自HRESULT的异常:0x8007007E)
这很奇怪,因为在编译期间没有错误.无论如何,我认为它试图告诉我,我需要引用一个额外的DLL:,sqlite3.dll但这不起作用.我的文件系统上有6个不同的DLL:ARM,x64和x86的调试版和发行版.我尝试将x86发布版本添加到我的项目中,但这会导致此异常:
无法添加对"C:\ Users\Leon\Documents\Visual Studio 2013\Projects\Googalytics\packages\SQLite\x86\sqlite3.dll"的引用.请确保该文件是可访问的,并且它是有效的程序集或COM组件.
令人遗憾的是,sqlite-net的文档很糟糕,它已经过时了(示例甚至不再起作用),它非常不完整,也没有提到手动添加DLL.所以我有两个问题:
编辑:我用来创建数据库的代码是:
private void InitializeDatabase()
{
var db = new SQLiteConnection("Googalytics");
db.CreateTable<Account>();
db.CreateTable<WebProperty>();
db.CreateTable<Profile>();
}
Run Code Online (Sandbox Code Playgroud)
我从这里打电话给那个方法:
InitializeDatabase();
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed …Run Code Online (Sandbox Code Playgroud) 我想使用此链接https://github.com/praeclarum/sqlite-net提供的sqlite-net .
不幸的是,入门文档是不够的.它甚至没有提到如何创建数据库.我试着查看这些示例,遗憾的是,示例已被破坏(无法编译,运行时错误等).
我可以在网上找到的最实用的教程是http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/
不幸的是,sqlite-net并不完全支持sqlite.org sqlite实现,因此使教程对praeclarum sqlite-net无用.
在教程中但在praeclarum sqlite-net中执行相同操作的等效方法是什么?
从教程
创建数据库(这是我卡住的地方)
SQLiteConnection.CreateFile("MyDatabase.sqlite");
Run Code Online (Sandbox Code Playgroud)
连接数据库
SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
Run Code Online (Sandbox Code Playgroud)
创建表格
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
填表
string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert …Run Code Online (Sandbox Code Playgroud) 我有两个简单的表格如下:
public class MediaPartner
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string PhoneNumber { get; set; }
public string CompanyName { get; set; }
public double Lat { get; set; }
public double Lng { get; set; }
public DateTime InsertedUtc { get; set; }
}
public class ImageGroup
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public List<MediaPartner> IdMediaPartner { get; set; }
public string ImagePath { get; set; }
public bool IsSent …Run Code Online (Sandbox Code Playgroud) 我的解决方案配置为"恢复包",但其中一个项目未能构建: -
3> C:\ Builds\1\xxxxx\xxxx.csproj(223,5):错误:此项目引用此计算机上缺少的NuGet包.启用NuGet Package Restore以下载它们.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105.丢失的文件是..\packages\System.Data.SQLite.Core.1.0.97.0\build \net45\System.Data.SQLite.Core.targets.
它可能是一个红鲱鱼,但上面的错误出现在包恢复之前的日志中,即
2> RestorePackages:
恢复NuGet包......
在违规项目的.csproj文件的末尾附近是这一<Target>部分,似乎产生了上述错误: -
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.97.0\build\net45\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.97.0\build\net45\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.97.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.97.0\build\net45\System.Data.SQLite.Core.targets'))" />
</Target>
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?我是否正确地假设这个检查是在解决方案的包甚至已经恢复之前发生的(因此它失败了)?我该如何解决?
解决方案中的其他项目(那些没有引用SQLite核心包的项目)可以很好地恢复它们的包,并且可以成功构建.
system.data.sqlite tfsbuild nuget sqlite-net nuget-package-restore
我正在尝试使用 MvvmCross 4 中的扩展。我想做的很简单:我有两个具有一对多关系的表,并且想要访问它。
我有两节课,BusLine并且BusLineGroup。每条 BusLine 都有一个 Group 作为外键。我在代码中所做的就是运行一个简单的 LINQ 查询来获取所有总线:
var testQuery =
from busLine in this._connection.Table<BusLine>()
select busLine;
Run Code Online (Sandbox Code Playgroud)
查询本身有效,但如果我检查返回对象的字段,组始终是null!。请参阅下面的类和表定义。
我究竟做错了什么?为什么总是一群人null?感谢您的帮助。
代码中的类:
public class BusLine
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
[ForeignKey(typeof(BusLineGroup))]
public int BusLineGroup { get; set; }
[ManyToOne]
public BusLineGroup LineGroup { get; set; }
}
public class BusLineGroup
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; …Run Code Online (Sandbox Code Playgroud) 因此,我正在尝试使用适用于iOS + Android的Xamarin设置跨平台应用.
我在PCL中包含了sqlite-net包,现在我对Windows 8或Silverlight(我都不需要支持)有依赖性问题.
如果我选择了支持silverlight的profile24这样的配置文件,我会收到以下错误:
错误CS0234:名称空间"System.Diagnostics"中不存在类型或命名空间名称"秒表".你错过了装配参考吗?(CS0234)
另一方面,如果我在Windows 8和Windows Phone 8中选择了profile49这样的配置文件,我会收到如下错误:
错误CS0117:'System.Threading.Thread'不包含`VolatileWrite'的定义(CS0117)
或者使用profile111(Windows 8 + Windows Phone 8.1):
错误CS0103:当前上下文中不存在名称"Thread"(CS0103)
事实是,我不需要支持这些平台.但是没有包括Xamarin.iOS + Xamarin.Android在内的个人资料.我被迫支持那些带来麻烦的平台.
我能做什么 ?
我有一个UWP与数据库一起使用的项目Sqlite。我添加sqlite-net-pcl到我的参考文献中。REGEXP我想在查询中使用,select但它给了我no such function: REGEXP. 我搜索了错误,但结果是关于SQLiteFunction此处未定义的。我应该怎么办?
我有一个简单的实体:
[Table("History")]
public class History
{
[PrimaryKey, AutoIncrement, Column("_id")]
public int Id { get; set; }
[Indexed(Name = "IDX_History", Order = 1, Unique = true)]
public int Prefix { get; set; }
[Indexed(Name = "IDX_History", Order = 2, Unique = true)]
public int Stem { get; set; }
[Indexed(Name = "IDX_History", Order = 3, Unique = true)]
public int Suffix { get; set; }
[Indexed(Name = "IDX_Favourite")]
public bool IsFavourite { get; set; }
public DateTime LastViewed { get; set; …Run Code Online (Sandbox Code Playgroud) 我最近将我的两个项目都移到了SQLite.net-pcl。到目前为止,我遇到了许多问题,这是我的最新情况。每当我在iOS上运行我的应用程序时,它都会崩溃,并显示SQLite.SQLiteException:约束。Android在同一PCL上运行,并且会在第一次运行,但之后会给我SQLite.SQLiteException:约束,直到删除应用程序存储。不知道还有什么可以在这里尝试。
代码示例:-
宾语
using System;
namespace App.LocalObjects
{
[Preserve(AllMembers = true)]
public class LocalArticle
{
[SQLite.PrimaryKey, SQLite.Column("articleObjectId")]
public string objectId { get; set; }
public DateTime createdAt { get; set; }
public DateTime updatedAt { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Url { get; set; }
public int Status { get; set; }
public LocalArticle()
{
this.objectId = " ";
this.Title = " ";
this.Description = " …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的项目从SQLite.Net-PCL转换为sqlite-net-pcl(最新的稳定版本; 1.3.1),正如它在Xamarin处理数据库时说的那样,但是当我安装它时,它必须安装40个软件包(左右)如下所列
Microsoft.NETCore.Platforms 1.0.1
Microsoft.NETCore.Targets 1.0.1
runtime.native.System 4.0.0
SQLitePCLRaw.core 1.1.2
SQLitePCLRaw.bundle_green 1.1.2
System.Collections 4.0.11
System.Collections.Concurrent 4.0.12
System.Diagnostics.Debug 4.0.11
System.Diagnostics.Tools 4.0.1
System.Diagnostics.Tracing 4.1.0
System.Globalization 4.0.11
System.IO 4.1.0
System.IO.Compression 4.1.0
System.Linq 4.1.0
System.Linq.Expressions 4.1.0
System.Net.Http 4.1.0
System.Net.Primitives 4.0.11
System.ObjectModel 4.0.12
System.Reflection 4.1.0
System.Reflection.Extensions 4.0.1
System.Reflection.Primitives 4.0.1
System.Resources.ResourceManager 4.0.1
System.Runtime 4.1.0
System.Runtime.Extensions 4.1.0
System.Runtime.InteropServices 4.1.0
System.Runtime.Numerics 4.0.1
System.Text.Encoding 4.0.11
System.Text.Encoding.Extensions 4.0.11
System.Text.RegularExpressions 4.1.0
System.Threading 4.0.11
System.Runtime.InteropServices.RuntimeInformation 4.0.0
System.Threading.Tasks 4.0.11
System.Xml.ReaderWriter 4.0.11
System.Xml.XDocument 4.0.11
NETStandard.Library 1.6.0
sqlite-net-pcl 1.3.1
Run Code Online (Sandbox Code Playgroud)
我知道它需要一些软件包,但对我来说似乎有很多软件包.我正在使用Xamarin.Forms版本2.3.3.180(最新的稳定版)
如果我继续安装,会发生这样的错误
Could not …Run Code Online (Sandbox Code Playgroud)