2017-03-19 1 views
2

Sqlite-netを使用しようとしている新しいXamarin Formsアプリケーションがあります。 ORMのSqlite-Net拡張。私はThis guideに続いてn:nを作成しました。ここに私の二つのオブジェクト、並びにそれらの中間オブジェクトです:Sqlite-net拡張機能を使用した多対多の関係、NotSupportedExceptionの取得:System.Collections.Generic.Listについて知らない

国家が私のアプリの出発点に、

using Sqlite; 
using SQLiteNetExtensions.Attributes; 
using System.Collections.Generic; 

namespace MyNamespace.Models 
{  
    public class Nation 
    { 
     [PrimaryKey, AutoIncrement] 
     public int Id { get; set; } 

     public string Name { get; set; } 

     public string Adjective { get; set; } 

     public double Frequency { get; set; } 

     [ManyToMany(typeof(NationFirstName))] 
     public List<FirstName> FirstNames { get; set; } 
    } 
} 

using SQLite; 
using SQLiteNetExtensions.Attributes; 
using System.Collections.Generic; 

namespace MyNamespace.Models 
{ 
    public class FirstName 
    { 
     [PrimaryKey, AutoIncrement] 
     public int Id { get; set; } 

     public string Name { get; set; } 

     [ManyToMany(typeof(NationFirstName))] 
     public List<Nation> Nations { get; set; } 
    } 
} 

NationFirstName

using SQLite; 
using SQLiteNetExtensions.Attributes; 

namespace OffseasonGM.Models 
{ 
    public class NationFirstName 
    { 
     [ForeignKey(typeof(Nation))] 
     public int NationId { get; set; } 

     [ForeignKey(typeof(FirstName))] 
     public int FirstNameId { get; set; } 
    } 
} 

だから、 App.xaml.cs、まずNationFirstNameRepositoryを作成しようとしますが、これはうまくいきます。次に、NationRepositoryを作成しようとします。ここで、コンストラクターで例外が発生します。 CreateTable()ライン上:

[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Don't know about System.Collections.Generic.List`1[OffseasonGM.Models.FirstName] 

NationRepository.cs

using MyNamespace.Models; 
using SQLite; 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Reflection; 
using System.Threading.Tasks; 

namespace MyNamespace.Assets.Repositories 
{ 
    public class NationReposistory 
    { 
     SQLiteConnection connection; 

     public NationReposistory(string dbPath) 
     { 
      connection = new SQLiteConnection(dbPath); 
      var entriesCreatedCount = connection.CreateTable<Nation>(); 
      if (entriesCreatedCount < 1) 
      { 
       SeedNations(); 
      } 
     } 

     public void AddNewNation(string name, string adjective, double frequency) 
     { 
      try 
      { 
       connection.Insert(new Nation { Name = name, Adjective = adjective, Frequency = frequency }); 
      } 
      catch (Exception e) 
      { 
       //TODO: Error handling. 
      } 
     } 

     public List<Nation> GetAllNations() 
     { 
      return connection.Table<Nation>().ToList(); 
     } 

     private void SeedNations() 
     { 
      var assembly = typeof(MainPage).GetTypeInfo().Assembly; 
      var stream = assembly.GetManifestResourceStream("MyNamespace.Nations.txt"); 
      using (var reader = new StreamReader(stream)) 
      { 
       var line = reader.ReadLine().Split('|'); 
       var name = line[0]; 
       var adjective = line[1]; 
       var frequency = double.Parse(line[2]); 
       AddNewNation(name, adjective, frequency); 
      } 
     } 
    } 
} 

私は順不同で何かをする、または完全に何かを忘れているだろうか?どんなアドバイスにも非常に感謝しています。

答えて

0

ここに同じエラーがあります。 PCLを含むすべてのナゲットをアンインストールし、binフォルダとobjフォルダを削除し、ソリューションをクリーンアップし、SQLiteNetExtensions 1.3.0とSQLite.Net-PCL 3.1.1ナゲットを追加して、もう一度クリーンアップして再構築します。私のために働いて、私はこれらのパッケージの新しいバージョン間にいくつかの非互換性があると思います。

希望すると便利です。

関連する問題