Search code examples
c#sqlitetype-conversionwindows-store-appssqlite-net

Can I use a List of String in a class intended for SQLite?


What limitations are there on data types used in a class that will be used by SQLite-net to represent a table? Specifically, can I use this:

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

...or will I need this:

public string[] CoconutWaterBrands { get; set; }

...or something else altogether?


Solution

  • ORMs (aka abstraction leak) will have this kind of problem. The fields in the class will correspond to columns in the table. If you use List or arrays then the ORM will either have to somehow combine those values in the list in a single column, for that it will have to choose some kind of separator and what if the separator appears inside your string value, ultimately you will slowly find your self in rabbit hole.

    I don't think SQLite-net support arrays/list. You will need to use string (and split and join it as required) or create a new table to represent the one-to-many relationship.