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
Sqlite.net扩展名,无法使用GetWithChildren获取数据_Sqlite_Sqlite Net_Sqlite Net Extensions_Sqlite.net - Fatal编程技术网

Sqlite.net扩展名,无法使用GetWithChildren获取数据

Sqlite.net扩展名,无法使用GetWithChildren获取数据,sqlite,sqlite-net,sqlite-net-extensions,sqlite.net,Sqlite,Sqlite Net,Sqlite Net Extensions,Sqlite.net,我正在创建一个数据库,其中有几个类作为其他类的子类。使用外键写入可以很好地工作,但是当我尝试获取数据时,它会抛出错误: SQLiteNetExtensions.dll中发生类型为“SQLiteNetExtensions.Exceptions.IncorrecrelationshipException”的未处理异常 其他信息:MatchDetail.timeline:OneToOne关系中至少有一个实体必须具有外键 这是我的创建代码: SQLiteConnection db = new SQLit

我正在创建一个数据库,其中有几个类作为其他类的子类。使用外键写入可以很好地工作,但是当我尝试获取数据时,它会抛出错误:

SQLiteNetExtensions.dll中发生类型为“SQLiteNetExtensions.Exceptions.IncorrecrelationshipException”的未处理异常

其他信息:MatchDetail.timeline:OneToOne关系中至少有一个实体必须具有外键

这是我的创建代码:

SQLiteConnection db = new SQLiteConnection(new SQLite.Net.Platform.Win32.SQLitePlatformWin32(), "Matches.db3");
db.CreateTable<ParticipantIdentity>();
db.CreateTable<MatchDetail>();
db.CreateTable<Timeline>();
db.InsertWithChildren(md, true);
var m = db.GetWithChildren<MatchDetail>(matchId, true);
SQLiteConnection db=newsqliteconnection(new SQLite.Net.Platform.Win32.SQLitePlatformWin32(),“Matches.db3”);
db.CreateTable();
db.CreateTable();
db.CreateTable();
db.InsertWithChildren(md,true);
var m=db.GetWithChildren(matchId,true);
我的班级:

[Table("Matches")]
public class MatchDetail
{
    [PrimaryKey]
    public long matchId { get; set; }
    public int mapId { get; set; }
    [JsonConverter(typeof(DateTimeConverterFromLong))]
    public DateTime MatchCreation { get; set; }
    public long matchDuration { get; set; }
    public MatchMode matchMode { get; set; }
    public MatchType matchType { get; set; }
    public string matchVersion { get; set; }

    public string platformId { get; set; }
    public Queuetype queueType { get; set; }
    public Region region { get; set; }
    public Season season { get; set; }

    [ForeignKey(typeof(Timeline), Name = "TimelineId"), Indexed]
    public int timelineId { get; set; }
    [OneToOne("TimelineId", CascadeOperations = CascadeOperation.All)]
    public Timeline timeline { get; set; }

    [ForeignKey(typeof(ParticipantIdentity), Name = "ParticipantId"), Indexed]
    public int participantIdentitiesId { get; set; }
    [ManyToOne("ParticipantId", CascadeOperations = CascadeOperation.All)]
    public List<ParticipantIdentity> participantIdentities { get; set; }
}
[表(“匹配项”)]
公共类匹配细节
{
[主密钥]
公共长匹配ID{get;set;}
公共int mapId{get;set;}
[JsonConverter(类型(DateTimeConverterFromLong))]
公共日期时间匹配创建{get;set;}
公共长匹配持续时间{get;set;}
公共匹配模式匹配模式{get;set;}
公共匹配类型匹配类型{get;set;}
公共字符串匹配版本{get;set;}
公共字符串platformId{get;set;}
公共队列类型队列类型{get;set;}
公共区域区域{get;set;}
公共季节{get;set;}
[外键(typeof(Timeline),Name=“TimelineId”),索引]
public int timelineId{get;set;}
[OneTONE(“TimelineId”,级联操作=级联操作.All)]
公共时间线{get;set;}
[ForeignKey(typeof(participatentity),Name=“participatid”),索引]
public int participatientiesid{get;set;}
[ManyToOne(“ParticipantId”,CascadeOperations=CascadeOperation.All)]
公共列表参与者身份{get;set;}
}
其他的类只是一个id和一些其他的基本类型,我一直在尝试解决这个问题,但它就是不想工作

编辑:

[ForeignKey(typeof(ParticipantIdentity))]
public int participantIdentitiesId { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<ParticipantIdentity> participantIdentities { get; set; }
[ForeignKey(typeof(participatentity))]
public int participatientiesid{get;set;}
[OneToMany(级联操作=级联操作.All)]
公共列表参与者身份{get;set;}
有误:

SQLiteNetExtensions.dll中发生类型为“SQLiteNetExtensions.Exceptions.IncorrecrelationshipException”的未处理异常

其他信息:MatchDetail.ParticipationIdentity:找不到OneToMany关系的外键


您手动指定外键名为“TimelineId”,但实际上外键名为“TimelineId”(注意第一个字母的大写)

更改此项:

[ForeignKey(typeof(Timeline), Name = "TimelineId"), Indexed]
public int timelineId { get; set; }
[OneToOne("TimelineId", CascadeOperations = CascadeOperation.All)]
public Timeline timeline { get; set; }
为此:

[ForeignKey(typeof(Timeline)]
public int timelineId { get; set; }
[OneToOne(CascadeOperations = CascadeOperation.All)]
public Timeline timeline { get; set; }
显式声明外键名称可能会导致重构问题,因此除非严格要求,否则这是推荐的方法



另一个关系被声明为
manytone
,但实际上它是
OneToMany
。要使其工作,必须更改属性类型并将外键移动到另一端

将关系更改为:

[ForeignKey(typeof(ParticipantIdentity), Name = "ParticipantId"), Indexed]
public int participantIdentitiesId { get; set; }
[ManyToOne("ParticipantId", CascadeOperations = CascadeOperation.All)]
public List<ParticipantIdentity> participantIdentities { get; set; }

查看SQLite网络扩展和更多示例。

感谢您的回答,但是我似乎无法让列表正常工作,因为它也找不到外键。[ForeignKey(typeof(ParticipatityIdentity))]public int participatityIdentitiesId{get;set;}[OneToMany(CascadeOperations=CascadeOperation.All)]public List participatityIdentities{get;set;}Whoops的类型错误,但仍然得到错误。它应该是typeof(List)我试着完全这样做,但是manytone被颠倒了,所以我把它换成了OneToMany,它仍然会抛出错误,请参阅我的编辑。另一个关系声明为
manytone
,但它是
OneToMany
,有关更多详细信息,请参阅我的编辑。
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<ParticipantIdentity> participantIdentities { get; set; }
[ForeignKey(typeof(MatchDetail)]
public int matchDetailId { get; set; }