0

I have a problem. I created the following class:

public class KnownDevice
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string IP { get; set; }
    public string MAC { get; set; }
    public string Type { get; set; }

    public List<TriangleRegistryObject> triangles { get; set; }
    public List<HexagonRegistryObject> hexagons { get; set; }
}

Now, I want to create a Database on the mobile phone itself, so I use the following code to create the table:

database = DependencyService.Get<ISQLite>().GetConnection();
database.CreateTable<KnownDevice>();

But the code crashes on the second line with the error:

System.NotSupportedException: 'Don't know about System.Collections.Generic.List`1

Now on the internet I found that it is not allowed to add a List to a database, but I need the data in that list, so I have no idea how I can fix this problem. The list can contain arround 25 rows!

Any idea how I can solve this problem?

A. Vreeswijk
  • 822
  • 1
  • 19
  • 57

1 Answers1

0

List<TriangleRegistryObject> is not a valid type for a SQLite database value. Your type of List<TriangleRegistryObject> does not match any of the clrType == typeof(XXXX) statements, so you get that exception. You will need to rethink the class structure a little to be able to use SQLite-net like that.

For more details about the SQLite database, you could download the source file from the link for reference. https://learn.microsoft.com/zh-cn/samples/xamarin/xamarin-forms-samples/todo/

If you want to use ou could use List, you could use SQLite-Net Extensions instead of SQLite.

You could refer to the link. The SQLite-Net Extensions library direct to specific relationships in database. How can you store lists of objects in SQLite.net?

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17