标签: sqlite-net

Xamarin项目中SQLite-Net的通用存储库

我想知道是否有办法为我的Xamarin项目编写通用存储库,而不是为我的对象中的每个实体编写不同的存储库.Xamarin Tasky Pro示例为Task实体提供了一个Repository,因为它是它拥有的唯一实体.

在我自己的项目中,我有多个实体,所以我的问题是如何使以下客户存储库变得通用,以便ProductManager,EmployeeManager等可以使用它.如果你知道一个例子或博客文章,请指出我正确的方向

namespace App.DataLayer
{
    public class CustomerRepository
    {
        private ProntoDatabase _db = null;
        protected static string DbLocation;
        protected static CustomerRepository Me;

        static CustomerRepository()
        {
            Me = new CustomerRepository();
        }

        protected CustomerRepository()
        {
            //set the db location;
            DbLocation = DatabaseFilePath;

            //instantiate the database
            _db = new ProntoDatabase(DbLocation);
        }


        public static string DatabaseFilePath
        {
            get
            {
                const string sqliteFilename = "CustomerDB.db3";
                var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                var path = Path.Combine(libraryPath, sqliteFilename);
                return path;
            }
        }


        // CRUD (Create, Read, …
Run Code Online (Sandbox Code Playgroud)

c# repository-pattern xamarin sqlite-net

23
推荐指数
1
解决办法
1万
查看次数

类属性不包括在sqlite数据库列中

我有一个实体类

  public class someclass
  {
      public string property1 {get; set;}
      public string property2 {get; set;}
      public string property3 {get; set;}
  }
Run Code Online (Sandbox Code Playgroud)

并使用sqlite连接类obj DB我正在创建表

  Db.CreateTableAsync<someclass>().GetAwaiter().GetResult();
Run Code Online (Sandbox Code Playgroud)

我想要实现的是,我不希望sqlite在表中创建列property3.有没有办法实现这个目标?

我正在使用SQLiteAsync库来存储Windows应用程序.

c# sqlite windows-runtime windows-store-apps sqlite-net

22
推荐指数
2
解决办法
1万
查看次数

C#SQLite-net定义多列唯一

我见过对SQLite-net中支持多列唯一约束的更改的引用.我知道它可以直接用sqlite完成,但我更喜欢用sqlite-net方法做​​事.什么是多列唯一的语法.单个列上方的[唯一]是唯一的.

c# xamarin sqlite-net

16
推荐指数
1
解决办法
6323
查看次数

表仅在实际设备上没有(公共)列

我有最简单的应用程序,我以为在我全神贯注之前我会在我的设备上尝试.但是,当我在iPhone上运行它时,我收到了最奇怪的错误消息(与我的macbook上的模拟器相关).

表没有(公共)列.

我正在使用SQLite.Net PCL,我已经从git hub构建了它,因为我遇到了一些问题,否则没有IOS的平台dll.

相关代码.

在我的模型中我有这个:

public class Setting
{
    [PrimaryKey, AutoIncrement]
    public long Id { get; set; }

    [Indexed]
    public string Key { get; set; }

    public string Value { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

抛出此错误消息的代码很简单:

using (SQLiteConnection db = GetCon ()) {

            db.CreateTable<Setting> ();
}
Run Code Online (Sandbox Code Playgroud)

但在我看来,最奇怪的是这个代码在模拟器上工作正常,但崩溃了iphone本身的应用程序.

如果有人有一些想法会很棒.

编辑:此错误在此文件行380 上的SQLite.Net-PCL库上引发,但在设备上而不在模拟器上.

c# iphone ios xamarin sqlite-net

16
推荐指数
1
解决办法
1497
查看次数

无法在Mobile上运行的通用Windows应用程序中加载DLL sqlite3

我正在开发一个UWP.我正在使用sqlite-net-pcl库.将我的应用程序从RC升级到RTM后,我收到运行时错误 - 无法找到sqlite3.dll - 如果它在Mobile模拟器或设备上运行.在我添加了对C++ 2013 Runtime Package的引用并在Local Machine中运行它之后,它完美地工作了.

例外消息:

消息"'SQLitePCL.raw'的类型初始化程序引发了异常." 串

innerexception消息:

{"无法加载DLL的sqlite3":找不到指定的模块.(HRESULT异常:0x8007007E)"} System.Exception {System.DllNotFoundException}

当然我无法添加对"Sqlite for Universal App Platform"的引用,因为我发现了以下错误

严重性代码说明项目文件行错误有效负载包含两个或多个具有相同目标路径"sqlite3.dll"的文件.源文件:C:\ Program Files(x86)\ Microsoft SDKs\UAP\v0.8.0.0\ExtensionSDKs\SQLite.UAP.2015\3.8.11.1\Redist\Debug\ARM\sqlite3.dll C:\ Users\sMavrikis .nu​​get\packages\SQLitePCL.raw_basic\0.7.1\build \native\sqlite3_dynamic\winrt81\arm\sqlite3.dll TestApp1

sqlite sqlite-net uwp

15
推荐指数
2
解决办法
1万
查看次数

我可以在用于SQLite的类中使用String列表吗?

SQLite-net将用于表示表的类中使用的数据类型有哪些限制?具体来说,我可以使用这个:

public List<string> CoconutWaterBrands { get; set; }
Run Code Online (Sandbox Code Playgroud)

......或者我需要这个:

public string[] CoconutWaterBrands { get; set; }
Run Code Online (Sandbox Code Playgroud)

......还是别的什么?

c# sqlite type-conversion windows-store-apps sqlite-net

14
推荐指数
3
解决办法
4588
查看次数

Sqlite扩展无法按预期工作

我正在开发一个WinRT应用程序.我想使用sqlite-net-extensions到的支持OneToMany,ManyToMany.

using SQLiteNetExtensions.Attributes;
using SQLite;

[Table("WorkFlow")]
public class Workflow
{
    [PrimaryKey, AutoIncrement]
    public int WorkflowId { get; set; }
    public string Name { get; set; }
    public int Revision { get; set; }
    [OneToMany]
    public List<Step> Steps { get; set; }
}

[Table("Step")]
public class Step
{
    public string Type { get; set; }
    public string Description { get; set; }
    [ManyToOne]
    public Workflow Workflow { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试为数据库生成表时,它会引发异常:

app_name.exe中出现"System.NotSupportedException"类型的异常但未在用户代码中处理其他信息:不了解System.Collections.Generic.List`1 [app_name.Model.modelName]

这来自 …

c# windows-runtime windows-store-apps sqlite-net sqlite-net-extensions

10
推荐指数
2
解决办法
4630
查看次数

在两个模型之间创建ManyToMany关系

我是创建Windows应用商店应用的新手,需要使用数据库.我已经决定使用sqlite并使用sqlite-net包.但是,我不确定如何在两个模型之间创建m2m关系.

class ModelA
{
     [PrimaryKey, AutoIncrement]
     public int Id { get; set; }
     public string name { get; set; }
     <relationship to ModelB>
} 


class ModelB
{
     [PrimaryKey, AutoIncrement]
     public int Id { get; set; }
     public string name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我必须使用清单吗?还是一个字节[]?我怎样才能保证财产受到限制ModelB

c# sqlite sqlite-net

9
推荐指数
1
解决办法
2800
查看次数

如何在Windows 10 C#中更新sqlite.net pcl中的行?

我有行ID,然后我将更新其他值.

我不知道如何更新我的价值观!我的表:

 class MyTable
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Date { get; set; }
    public string Volumes { get; set; }
    public string Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

其他信息:

 string path;
    SQLite.Net.SQLiteConnection conn;

    public updatepage()
    {
        this.InitializeComponent();
        path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "ccdb.sqlite");

        conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);

        conn.CreateTable<MyTable>();
    }
Run Code Online (Sandbox Code Playgroud)

c# sqlite sqlite-net windows-10

9
推荐指数
1
解决办法
5455
查看次数

如何使用 SQLite.Net-PCL 制作 SQLite 外键

在 UWP 中,我享受使用 SQLite.Net-PCL 的好处,创建要在应用程序中使用的类作为 ObservableCollections 以绑定到 GridView。在包含 SQLiteNetExtensions 以构建带有外键的数据库后,我注意到在 SQLite Maestro 中查看数据库时并未真正创建外键。而是创建索引。 如果 SQLiteNetExtensions 并没有真正创建外键,那么使用它有什么好处?

使用 LAMDA 表达式或 LINQ 进行查询时,可能不需要外键(稍后在创建数据库后的应用程序中)。 如果我在不使用 SQLite.Net-PCL 的情况下执行查询以创建带有外键的表,我是否仍然可以使用 SQLite.Net-PCL 继续将 ObservableCollections 绑定到 GridViews?

示例数据库:

[Table("Book")]
public class Book
{
    [PrimaryKey, AutoIncrement, Column("ID")]
    public int ID { get; set; }
    [Column("Name")]
    public string Name { get; set; }

    [ManyToMany]
    public List<Checkout> Checkout { get; set; }
}

[Table("School")]
public class School
{
    [PrimaryKey, AutoIncrement, Column("ID")]
    public int ID { get; set; }
    [Column("Name")]
    public string …
Run Code Online (Sandbox Code Playgroud)

c# sqlite-net sqlite-net-extensions uwp

9
推荐指数
1
解决办法
8299
查看次数