SQLite.SQLiteException in Xamarin.Android when trying to create a table

I am trying to create a simple local SQLite database using Xamarin.Android. Code for this:

string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
SQLiteConnectiondb = new SQLiteConnection (Path.Combine (folder, "Experimental.db"));
db.CreateTable<Employee>();

      

My Employee class:

[Table("Employees")]
    public class Employee
    {
        [PrimaryKey, AutoIncrement]
        int Id { get; set; }

        string Name { get; set; }

    }

      

The exception that I get when the code reaches the db.CreateTable value:

 SQLite.SQLiteException: near ")": syntax error
  at at SQLite.SQLite3.Prepare2 (intptr,string) <IL 0x0002c, 0x00160>
  at at SQLite.SQLiteCommand.Prepare () <IL 0x00011, 0x0008f>
  at at SQLite.SQLiteCommand.ExecuteNonQuery () <IL 0x00013, 0x000b3>
  at at SQLite.SQLiteConnection.Execute (string,object[]) <IL 0x00041, 0x001ab>
  at at SQLite.SQLiteConnection.CreateTable (System.Type,SQLite.CreateFlags) <IL 0x000a4, 0x005cb>
  at at SQLite.SQLiteConnection.CreateTable<Core.Employee> (SQLite.CreateFlags) <0x00063>

      

To my inexperienced eyes, this looks like a problem related to SQLite itself. Has anyone else encountered this, and if so, what was your job?

+3


source to share


2 answers


Make the properties of the Employee class public so that SQLite can see them when creating columns for your table:



[Table("Employees")]
public class Employee
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string Name { get; set; }

}

      

+6


source


The problem is the linker options, sometimes the SQLite-net package is not associated with your project. It is necessary to check the linker behavior, only in the SDK assemblies for links to iOS and mtouch: - linkskip = SQLite-net , then its work.



0


source







All Articles