标签: sqlite-net-extensions

如何在 SQLite-Net 扩展中指定外键属性

如何指定引用特定属性而不是主键的外键?

例如 Stock 类有一个 uuid 属性。我想在使用此属性引用它的 Valuation 类中创建一个外键。

在以下示例中,行 [ForeignKey(typeof(Stock))] 引用 Stock 类的 ID 属性,但我需要它引用 UUID 属性。

我该怎么做?

public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string UUID { get; set; } 
    [MaxLength(8)]
    public string Symbol { get; set; }

    [OneToMany(CascadeOperations = CascadeOperation.All)]      // One to many relationship with Valuation
    public List<Valuation> Valuations { get; set; }
}

public class Valuation
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Stock))]     // Specify …
Run Code Online (Sandbox Code Playgroud)

c# sqlite-net-extensions

4
推荐指数
1
解决办法
8600
查看次数

Sqlite-net 扩展关系始终为空

我正在尝试使用 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)

c# mvvmcross sqlite-net sqlite-net-extensions

3
推荐指数
1
解决办法
1333
查看次数

Android - 'SQLite.SQLiteConnection'的类型初始化程序引发了异常.---> System.DllNotFoundException:e_sqlite3

在我们的Xamarin Android项目中,我们试图从sqlite-net切换到官方的sqlite-net-pcl包.

在此输入图像描述

但是在创建新的SQLiteConnection后进行此切换后,我遇到以下异常:

'SQLite.SQLiteConnection'的类型初始值设定项引发了异常.---> System.DllNotFoundException:e_sqlite3

完全例外:

Xamarin引起的:android.runtime.JavaProxyThrowable:System.TypeInitializationException:'SQLite.SQLiteConnection'的类型初始值设定项引发异常.---> System.DllNotFoundException:e_sqlite3 at(wrapper managed-to-native)SQLitePCL.SQLite3Provider_e_sqlite3 + NativeMethods:siteite3_libversion_number()at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()[0x00000] in:0 at SQLitePCL.raw. SQL4中的Setitevider(SQLitePCL.ISQLite3Provider imp)[0x00000]:SQLitePCL.Batteries_V2.Init()[0x0000d]中的<1125db7e18f0475797b2764ec6653cf1>:0中的/,/ Users/fak中的SQLite.SQLiteConnection..cctor()[0x00000]中的0 /Dropbox/Projects/sqlite-net/src/SQLite.cs:171 ---内部异常堆栈跟踪结束---在mono.android.view.View_OnClickListenerImplementor上的mono.android.view.View_OnClickListenerImplementor.n_onClick(本机方法) .onClick(View_OnClickListenerImplementor.java:30)在android.view.View.performClick(View.java:4780)的android.view.View $ PerformClick.run(View.java:19866)android.os.Handler.handleCallback( Handler.java:739)在android.os.Handler.dispatchMessage(Handler.jav a:95)在android.app.Looper.loop(Looper.java:135)的android.app.ActivityThread.main(ActivityThread.java:5254)java.lang.reflect.Method.invoke(Native Method)at java位于com.android.internal.os.ZygoteInit.main的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)中的.lang.reflect.Method.invoke(Method.java:372)(ZygoteInit)的.java:698)

在日志中我可以看到以下信息:

12-01 10:43:05.356 D/Mono(11194):DllImport试图加载:'e_sqlite3'.12-01 10:43:05.358 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.覆盖/libe_sqlite3' :"dlopen的失败:库"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/ 覆盖/libe_sqlite3"找不到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.override /libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.覆盖 /libe_sqlite3.so"未找到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/ system/lib/libe_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86 // system/lib/libe_sqlite3"找不到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/system/lib/libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib /x86//system/lib/libe_sqlite3.so"未找到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'libe_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/libe_sqlite3"未找到".12-01 10:43:05.361 D/Mono(11194):DllImport错误加载库'libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.所以"没找到".12-01 10:43:05.361 D/Mono(11194):DllImport错误加载库'e_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/e_sqlite3"未找到".12-01 10:43:05.362 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.覆盖/libe_sqlite3' :"dlopen的失败:库"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/ 覆盖/libe_sqlite3"找不到".12-01 10:43:05.364 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.override /libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.覆盖 …

android xamarin.android xamarin sqlite-net sqlite-net-extensions

3
推荐指数
1
解决办法
3162
查看次数

UpdateWithChildren不更新列表(OneToMany)关系

以下是一些重现问题的示例代码:

客户类

public class Customer
{
    private int _id;

    [Column("_id"), PrimaryKey, AutoIncrement]
    public int Id
    {
        get { return _id; }
        set
        {
            if (value != _id)
            {_id = value;}
        }
    }

   private string _name;

   [Column("_name")]
   public string Name
   {
       get { return _name; }
       set
       {
           if (value != _name)
           {_name = value;}
       }
   }

   private List<Order> _orders;
   [OneToMany(CascadeOperations = CascadeOperation.CascadeInsert | CascadeOperation.CascadeRead | CascadeOperation.CascadeDelete)]
   public List<Order> Orders
   {
       get { return _orders; }
       set
       {
           if (_orders != …
Run Code Online (Sandbox Code Playgroud)

sqlite-net-extensions

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

NullReferenceException使用连接字符串属性上的Where查询SQLite数据库

我正在尝试使用以下代码选择记录:

Location item = connection
  .Table<Location>()
  .Where(l => l.Label.Equals(label))
  .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

这导致:

System.NullReferenceException:未将对象引用设置为对象的实例.

当我尝试相同的,在不同的属性(邮政编码),它没有找到记录时一切正常:

Location item = connection
  .Table<Location>()
  .Where(l => l.Postcode.Equals(label))
  .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

这是位置类:

// These are the Locations where the Stock Take Sessions are done
public class Location : DomainModels, IComparable<Location>
{
    [JsonProperty("id"), PrimaryKey]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Street { get; set; }
    public int Number { get; set; }
    public string Postcode { get; set; }
    public …
Run Code Online (Sandbox Code Playgroud)

c# android sqlite-net-extensions

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

SQLite异步连接缺少WithChildren方法

我有一个使用SQLite的Xamarin Forms项目。我有一个父子模型,在相关字段上具有正确的外键,ManyToOne和级联选项。

我一直在这样的db方法中使用Scott Hanselman的AsyncLock类(http://www.hanselman.com/blog/ComparingTwoTechniquesInNETAsynchronousCoordinationPrimitives.aspx),如下所示:

public async Task<List<Client>> GetAllAsync()
{
    List<Client> clients = new List<Client>();
    using (await SQLiteBase.Mutex.LockAsync().ConfigureAwait(false))
    {
       //SQLiteAsyncConnection _connection is set up elsewhere...
        clients = await _sqLiteBase._connection.Table<Client>().ToListAsync().ConfigureAwait(false);
    }           

return clients;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止没有问题。我面临的问题是,我看不到此连接上的级联操作。我添加了一个带有SQLiteConnection- WithChildren方法的normal ,但是我需要使用SQLiteAsyncConnection连接。

我引用了SQLite.Net,SQLiteNetExtensions,SQLite.Net.Async和SQLitePCL.raw。

为什么WithChildren在异步连接对象上看不到〜方法?

c# xamarin.forms sqlite-net-extensions

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

GetAllWithChildren()性能问题

我在以下代码中使用SQLite-Net Extensions 从Sqlite数据库中检索1000行及其子关系:

var list =
SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren<DataModel>(connection);
Run Code Online (Sandbox Code Playgroud)

问题是表现很尴尬.因为GetAllWithChildren()返回List而不是Enumerable.是否存在使用Sqlite.net扩展将记录加载到Enumerable的任何方法?

我现在使用Sqlite.net中的Table()方法,将获取的行加载到Enumerable中但我不想使用它,因为它不理解关系并且根本不加载子实体.

c# sqlite xamarin sqlite-net sqlite-net-extensions

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