我正在尝试让多对多数据库关系在我的数据库中(当前)在 Android Samsung S6 移动设备上工作。为此,我使用 SQLite.Net-PCL 3.0.5 和 SQLiteNetExtensions 1.3.0。
我有简单的 SQlite 访问工作正常,但现在我试图建立多对多关系(通过链接表),sqlite-net-extensions 在我调用时抛出
m_DatabaseConnection.UpdateWithChildren(文章);
异常(exception)是:
System.MissingMethodException: Method 'SQLiteConnection.InsertAll' not found.
这很奇怪,因为我反汇编了 dll 并确定它确实存在。我的数据类的结构是:
public class Article : BaseModel
{
public Article()
{
Audience = new List<Tag>();
Content = new List<Tag>();
Weather = new List<Tag>();
}
...
[ManyToMany(typeof(ArticleTag))]
public List<Tag> Audience { get; set; }
[ManyToMany(typeof(ArticleTag))]
public List<Tag> Content { get; set; }
[ManyToMany(typeof(ArticleTag))]
public List<Tag> Weather { get; set; }
....
}
public class ArticleTag
{
[ForeignKey(typeof(Article))]
public int ArticleID { get; set; }
[ForeignKey(typeof(Tag))]
public int TagID { get; set; }
}
public class Tag : BaseModel
{
...
}
public class BaseModel
{
public BaseModel()
{
}
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public bool Dirty { get; set; }
}
那我做错了什么?我需要包含不同版本的 SQLite.Net-PCL 吗?我尝试下载和编译扩展项目,但似乎有错误(我不得不卸载 iOS 项目,因为我没有 iOS 的许可证,但其余的应该已经编译)。
有什么想法吗?
-- 更新---
似乎有问题的行必须在“WriteOperations.cs”中:
private static void UpdateManyToManyForeignKeys(this SQLiteConnection conn, object element, PropertyInfo relationshipProperty)
{
...
conn.InsertAll(missingIntermediateObjects);
..
}
然后这会转到 SQLiteExtensions-MvvmCross 并且一定找不到接口(interface)的实现。所以,问题是,我需要其他 NuGet 包吗?
最佳答案
因此,看起来这是对它的工作原理的误解和 1.3 被破坏的结合。
我回滚到 1.2.5,它不再抛出异常。但实际上并没有保存。然后我查看了项目源代码中包含的测试用例(可在此处获得:https://bitbucket.org/twincoders/sqlite-net-extensions),发现他没有直接保存多对多关系。相反,他插入了初始实体,然后对相同的实体调用 UpdateWithChildren 以填充链接表。这似乎有效。我不清楚为什么不将其整合到一个电话中,但它让我继续前进。
关于c# - 未找到方法 'SQLiteConnection.InsertAll',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33832214/