Don't know about System.Collections.Generic.List - SQLiteConnection.CreateTable<>
Hi, I'm new on SQLite. I made a research and decided to try, but on my first project, I'm stuck and I found no solution for my issue.
The error that I receive:
System.NotSupportedException: Don't know about System.Collections.Generic.List`1 [...Inventory]
My models:
public class Store
{
[PrimaryKey]
public int StoreID { get; set; }
public string SID { get; set; }
public string Name { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<Inventory> Inventories { get; set; }
}
public class Inventory
{
[PrimaryKey]
public int InventoryID { get; set; }
public DateTime CloseDate { get; set; }
public string InventoryType { get; set; }
public DateTime LastUpdated { get; set; }
public bool IsSuppressed { get; set; }
public bool DeletionConfirmed { get; set; }
[ForeignKey(typeof(Store))]
public int StoreID { get; set; }
[ManyToOne]
public Store Store { get; set; }
public string CloseDate_Description => CloseDate.ToString("MMMM dd, yyyy");
}
SQLiteConnection database;
database = DependencyService.Get<ISQLite>().GetConnection();
database.CreateTable<Store>();
Is there a solution for this? Thank you anyway. =)
Comments (6)
-
-
reporter Worked. I removed every SQLite package from Nuget, cleaned the solution and then installed SQLite-Net Extensions from Nuget on the PCL project and Android and iOS projects. But now, I can't instantiate a new SQLiteConnection on each platform. On SQLite-net-pcl package, my config was this:
iOS:
public class SQLite_iOS : ISQLite { public SQLite_iOS() { } public SQLiteConnection GetConnection() { var sqliteFilename = "Xamarindb.db3"; string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder var path = Path.Combine(libraryPath, sqliteFilename); // Create the connection var conn = new SQLiteConnection(path); // Return the database connection return conn; } }
Android:
public class SQLite_Android : ISQLite { public SQLite_Android() { } public SQLiteConnection GetConnection() { var sqliteFilename = "XamarinDB.db3"; string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder var path = Path.Combine(documentsPath, sqliteFilename); // Create the connection var conn = new SQLiteConnection(path); // Return the database connection return conn; } }
There's much more parameters that I need to pass on new SQLiteConnection, not only the path. Do you have an example of that? I still couldn't find one.
Thank you
-
If you're using SQLite-Net PCL version, it just requires the SQLitePlatform parameter:
new SQLiteConnection(new SQLitePlatformIOS(), DatabaseFilePath)
-
reporter It's everything working now. So: - Removed every SQLite reference that I installed from Nuget; - Installed SQLite-Net Extensions - Change the platform file as you suggested.
Thank you very much
-
reporter - changed status to resolved
-
I m getting the same issue but using SQLite-Net Extensions it gives me the error for XamrainAndroid Platform error
I m using Xamarin.Android
I have many posts in GitHub and everyone recommended to use this one SQLite-net-pcl
By following this link:
- Log in to comment
All SQLite-Net Extensions attributes inherit from sqlite.net
Ignore
attribute. If they are not ignored is because sqlite.net is usually a configuration issue related to having two different versions of sqlite.net on the project dependencies. Try removing sqlite.net dependency before adding SQLite-Net Extensions nuget package, so only one of them is included in the project libraries.