我现在正在寻找这个问题几个小时,这是非常逻辑他不知道能力(因为能力尚未制定),但你们知道如何解决这个问题吗?
这是我得到的错误信息: 不了解System.Collections.Generic.List`1 [pokedex.Ability]
我的课程: -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; }
}
我的数据库:
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
}
提前致谢!
答案 0 :(得分:2)
列表不是SQLite数据库值的有效类型。
查看以下有效类型:
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
}
}
答案 1 :(得分:0)
我认为这是因为您的Ability表定义中存在拼写错误。在ManyToMany属性中,你应该使用“口袋妖怪”而不是“Pokmemons”。另外,你的另一个表是“能力”,而不是“能力”。如果它没有帮助,请更新帖子......
答案 2 :(得分:-2)
请参阅例外类型:它是 NotSupportedException 。