У меня есть новое приложение Xamarin Forms, в котором я пытаюсь использовать расширения Sqlite-net и Sqlite-net для ORM. Я следовал этому руководству, чтобы создать n:n. Вот мои два объекта, а также их промежуточный объект:
нация
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; }
}
}
НацияИмя
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);
}
}
}
}
Я что-то делаю не по порядку или вообще что-то забываю? Очень благодарен за любой совет.