gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 06:18:56 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com