Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite.Net - Don't know about System.Collections.Generic.List fault - Xamarin Android

I'm searching for hours now on this problem and it is very logic he does not know Ability (because Ability is not made yet), But do you guys know how to fix this?

This is the fault message I get: Don't know about System.Collections.Generic.List`1[pokedex.Ability]

My classes: -Ability

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

    public String name{ get; set; }

    [ManyToMany (typeof(PokemonAbility))]
    public List<Pokemon> pokemon{ get; set; }

    public Ability (String n)
    {
        name = n;
    }
}

-Pokemon:

[Table ("Pokemon")]
public class Pokemon
{
    [PrimaryKey,AutoIncrement]
    public int DBId { get; set; }

    public int id { get; set; }

    public String name{ get; set; }

    public String type{ get; set; }

    public String image{ get; set; }

    public int Attack{ get; set; }

    public int speed{ get; set; }

    public int sp_atk{ get; set; }

    public int sp_def{ get; set; }

    public int defense{ get; set; }

    public string height{ get; set; }

    public String weight{ get; set; }

    public int hp{ get; set; }

    public String description{ get; set; }

    [ManyToMany (typeof(PokemonAbility))]
    public List<Ability> abilities{ get; set; }

    methods and consttuctor...


}

PokemonAbility:

[Table ("PokemonAbility")]
public class PokemonAbility
{
    public PokemonAbility ()
    {
    }

    [ForeignKey (typeof(Pokemon))]
    public int PokemonId { get; set; }

    [ForeignKey (typeof(Ability))]
    public int AbilityId { get; set; }
}

My DB:

public class NormalDatabase
{

    private String pathToDatabase;

    public NormalDatabase ()
    {
        var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
        pathToDatabase = Path.Combine (documents, "db_adonet.db");
    }

    //aanmaken van de tabel => met objecten pokemon
    public void CreateDatabase ()
    {
        using (var conn = new SQLite.SQLiteConnection (pathToDatabase)) {
            conn.DropTable<Pokemon> ();
            conn.DropTable<Ability> ();
            conn.DropTable<PokemonAbility> ();
            conn.CreateTable<Pokemon> ();  //here he fails ofc
            conn.CreateTable<Ability> ();
            conn.CreateTable<PokemonAbility> ();
        }
    other methods
    }

Thanks in advance!

like image 741
x_steven_xx Avatar asked Nov 27 '22 18:11

x_steven_xx


1 Answers

List is not a valid type for a SQLite database value.

Check out the valid types below:


    public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks)
    {
        var clrType = p.ColumnType;
        if (clrType == typeof(Boolean) || clrType == typeof(Byte) || clrType == typeof(UInt16) || clrType == typeof(SByte) || clrType == typeof(Int16) || clrType == typeof(Int32)) {
            return "integer";
        } else if (clrType == typeof(UInt32) || clrType == typeof(Int64)) {
            return "bigint";
        } else if (clrType == typeof(Single) || clrType == typeof(Double) || clrType == typeof(Decimal)) {
            return "float";
        } else if (clrType == typeof(String)) {
            int len = p.MaxStringLength;
            return "varchar(" + len + ")";
        } else if (clrType == typeof(DateTime)) {
            return storeDateTimeAsTicks ? "bigint" : "datetime";
            #if !NETFX_CORE
        } else if (clrType.IsEnum) {
            #else
        } else if (clrType.GetTypeInfo().IsEnum) {
            #endif
            return "integer";
        } else if (clrType == typeof(byte[])) {
            return "blob";
        } else if (clrType == typeof(Guid)) {
            return "varchar(36)";
        } else {
            throw new NotSupportedException ("Don't know about " + clrType); //Here the exception is thrown
        }
    }
like image 74
Saket Sinha Avatar answered Dec 04 '22 15:12

Saket Sinha