c# - 我可以在用于 SQLite 的类中使用字符串列表吗?

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

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

public List<string> CoconutWaterBrands { get; set; }

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

public string[] CoconutWaterBrands { get; set; }

...还是其他什么东西?

最佳答案

与 Sandy 的回答类似,在序列化/反序列化列表方面,您可以使用 SQLite-Net Extensions library 中的 Text blobbed properties .因此,例如在您的模型类中:

public class SomethingToDoWithCoconuts
{
    [TextBlob(nameof(CoconutWaterBrandsBlobbed))]
    public List<string> CoconutWaterBrands { get; set; }
    public string CoconutWaterBrandsBlobbed { get; set; } // serialized CoconutWaterBrands
}

来自 documentation on Text blobbed properties :

Text-blobbed properties are serialized into a text property when saved and deserialized when loaded. This allows storing simple objects in the same table in a single column.

Text-blobbed properties have a small overhead of serializing and deserializing the objects and some limitations, but are the best way to store simple objects like List or Dictionary of basic types or simple relationships. Text-blobbed properties require a declared string property where the serialized object is stored.

Text-blobbed properties cannot have relationships to other objects nor inverse relationship to its parent.

A JSON-based serializer is used if no other serializer has been specified using TextBlobOperations.SetTextSerializer method. To use the JSON serializer, a reference to Newtonsoft Json.Net library must be included in the project, also available as a NuGet package.

关于c# - 我可以在用于 SQLite 的类中使用字符串列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663984/

相关文章:

c# - OpenProcess 无法通过 id 打开现有进程(最后错误代码 : 1008)?

c# - 野田时间 - 带区域的一天开始/结束

c# - 如何获取字符串数组中对象列表的特定字段

c# - Nito.AsyncEx.AsyncLock 堆栈溢出,带有大量等待者和同步快速路径

haskell : Integer to Int with int signature

java - 可以将数据类型保存到变量吗? (数据类型 = 整数)?

types - 如何在 Kotlin 中正确处理大于 127 的字节值?

ios - sqlite for swift 不稳定

sqlite - 同一个 sqlite 数据库的不同连接可以同时开始事务吗?

java - 在树莓派上使用带有 Java 的 sqlite