5

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!

x_steven_xx
  • 51
  • 1
  • 3

3 Answers3

2

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
        }
    }

Saket Sinha
  • 81
  • 1
  • 5
0

I think it's because of typos in your Ability table definition. In ManyToMany attribute you should use "Pokemon" and not "Pokmemons". Also, another your table is "Ability" and not "Abilities". Update the post if it doesn't help...

Grisha
  • 713
  • 5
  • 13
  • I updated the code, It does not work yet. Same fault. Thx for the response! – x_steven_xx Nov 29 '15 at 10:35
  • You still have "AbilityId" inside the manytomany attribute, but the name of the column is "Id". The same is with Pokemon table. I think that you don't need to specify the column in the attribute - moreover, if later you'll want to change the name of the column, it will not refactor properly. Why not just write [ManyToMany(typeof(PokemonAbility))] ? – Grisha Nov 29 '15 at 15:01
  • I tried it without these specification ([ManyToMany(typeof(PokemonAbility))]) , but it gave the same fault, also if I just put Id en DBId, it does not know about the list. – x_steven_xx Nov 29 '15 at 15:27
  • OK, now it looks like that it doesn't load sqlite extensions. How did you add it? Do you use nuget? Try to remove both extensions and sqlite-net packages form the project and then add the extensions nuget. See this link for more information:http://stackoverflow.com/questions/23463849/sqlite-extension-is-not-working-as-expected – Grisha Nov 29 '15 at 16:01
-5

Please refer to the Exception Type too: It's of NotSupportedException.

See here: how to create collection (1:n) relation

Community
  • 1
  • 1
Kai Brummund
  • 3,538
  • 3
  • 23
  • 33
  • I think the OP does make his relations according to the answer in the article you're referring to ( I mean, of course, the second answer suggesting using the extensions - exactly what op uses). So I can't understand why the link you provide answers the question. – Grisha Nov 29 '15 at 07:55