Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Sqlite网络扩展的多对多关系,获取NotSupportedException:Don';我不知道System.Collections.Generic.List_Sqlite_Xamarin_Sqlite Net_Sqlite Net Extensions - Fatal编程技术网

使用Sqlite网络扩展的多对多关系,获取NotSupportedException:Don';我不知道System.Collections.Generic.List

使用Sqlite网络扩展的多对多关系,获取NotSupportedException:Don';我不知道System.Collections.Generic.List,sqlite,xamarin,sqlite-net,sqlite-net-extensions,Sqlite,Xamarin,Sqlite Net,Sqlite Net Extensions,我有一个新的XamarinForms应用程序,在其中我试图为ORM使用Sqlite网络和Sqlite网络扩展。我已经按照创建了n:n。这是我的两个对象,以及它们的中间对象: 国家 using Sqlite; using SQLiteNetExtensions.Attributes; using System.Collections.Generic; namespace MyNamespace.Models { public class Nation {

我有一个新的XamarinForms应用程序,在其中我试图为ORM使用Sqlite网络和Sqlite网络扩展。我已经按照创建了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; }
    }
}
因此,在我的应用程序的起点app.xaml.cs中,我尝试首先创建NationFirstNameRepository,它运行良好。接下来,我尝试创建NationRepository,在这里我在构造函数中得到一个异常。在CreateTable()行上:

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);
            }
        }
    }
}
使用MyNamespace.Models;
使用SQLite;
使用制度;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
运用系统反思;
使用System.Threading.Tasks;
命名空间MyNamespace.Assets.Repositories
{
公营国民议会
{
SQLiteConnection;
public NationRepository(字符串dbPath)
{
连接=新的SQLiteConnection(dbPath);
var entriesCreatedCount=connection.CreateTable();
如果(entriesCreatedCount<1)
{
联合国();
}
}
public void AddNewNation(字符串名称、字符串形容词、双频)
{
尝试
{
插入(新国家{名称=名称,形容词=形容词,频率=频率});
}
捕获(例外e)
{
//TODO:错误处理。
}
}
公共列表GetAllNations()
{
返回连接.Table().ToList();
}
联合国私营部门()
{
var assembly=typeof(主页).GetTypeInfo().assembly;
var stream=assembly.GetManifestResourceStream(“MyNamespace.Nations.txt”);
使用(变量读取器=新的流读取器(流))
{
var line=reader.ReadLine().Split(“|”);
变量名称=行[0];
变量形容词=行[1];
var frequency=double.Parse(第[2]行);
AddNewNation(名称、形容词、频率);
}
}
}
}
我是在做一些不正常的事情,还是完全忘记了什么?非常感谢您的建议。

这里也有同样的错误。 我卸载所有包含PCL的NUGET,删除bin和obj文件夹,清理解决方案,添加SQLiteNetExtensions 1.3.0和SQLite.Net-PCL 3.1.1 NUGET,再次清理并重建。对于我来说,我认为这些包的较新版本之间存在一些不兼容

希望这有帮助

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; }
    }
}
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Don't know about System.Collections.Generic.List`1[OffseasonGM.Models.FirstName]
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);
            }
        }
    }
}