如何使用带有复合键的SQLite-Net扩展 [英] How to use SQLite-Net Extensions with Composite keys

查看:107
本文介绍了如何使用带有复合键的SQLite-Net扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程:

Class1.cs:

Class1.cs:

[JsonObject(MemberSerialization.OptIn)]
public class Class1
{
    [PrimaryKey]
    [JsonProperty("key1")]
    public string Key1 { get; set; }

    [PrimaryKey]
    [JsonProperty("key2")]
    public string Key2 { get; set; }

    [PrimaryKey]
    [JsonProperty("key3")]
    public string Key3 { get; set; }

    [JsonProperty("normalStuff")]
    public string NormalStuff{ get; set; }

    [OneToMany(CascadeOperations = CascadeOperation.All)]
    [JsonProperty("customObjectList")]
    public List<CustomObject> CustomObjects { get; set; }
}

然后是我的CustomObject类:

And then my CustomObject class:

[JsonObject(MemberSerialization.OptIn)]
public class CustomObject
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Class1))]
    public string Class1Key{ get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("value")]
    public string Value { get; set; }
}

基本上,我要完成的工作是有一个表,其中包含到这些自定义对象的映射. SQLite-Net扩展甚至还支持此功能吗? MVVMCross SQLite社区软件包的最新版本支持组合键方面.当我尝试将上述数据结构保存到数据库中时,它将保存除我的CustomObjects之外的所有内容……这些最终为空.如果您需要更多信息以了解我要完成的工作,请告诉我!

Basically what I'm trying to accomplish is have a table that contains mappings to these custom objects. Is this even supported in SQLite-Net extensions? The composite keys aspect is supported in the newest version of the MVVMCross SQLite community package. When I try to save the above data structure to my DB it saves everything except for my CustomObjects... those end up being null. Let me know if you need any more information to understand what I'm trying to accomplish!

推荐答案

首先,感谢您对MvvmCross SQLite社区插件的贡献.

First, thank you for your contribution to MvvmCross SQLite Community plugin.

不幸的是,当前SQLite-Net扩展中不支持复合键,只有MvvmCross SQLite-Net的实现支持多个主键,这是最近的更改.

Sadly, there's currently no support for composite keys in SQLite-Net Extensions, only MvvmCross implementation of SQLite-Net supports multiple primary keys and it's a very recent change.

我将研究支持它所需的更改,但这需要一些时间. SQLite-Net扩展建立在以下假设的基础上:主键是唯一的,因此每个关系的外键也将是唯一的.这种调整将需要对体系结构和API进行一些深层次的更改.

I'll take a look at the changes required to support it, but it will take some time. SQLite-Net Extensions was built on top of the assumption that primary keys were unique and therefore foreign keys would be unique per relationship too. This adaptation would require some deep changes in the architecture and the API.

我正在考虑这样的事情,以避免当前正在使用的公共API发生更改:

I'm thinking in something like this to avoid changes in currently working public API:

[CompositeForeignKey(typeof(Class1), "key1", "key2", "key3"]
public Tuple<int, int, int> Class1Key { get; set; }

我创建了一个新在项目中发布以跟踪状态.

I've created a new issue in the project to keep track of the status.

这篇关于如何使用带有复合键的SQLite-Net扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆