我正在创建一个数据库,其中多个类作为其他类的子类。使用外键编写工作正常,但是当我尝试取回数据时,它会引发错误:
SQLiteNetExtensions.dll 中出现“SQLiteNetExtensions.Exceptions.IncorrectRelationshipException”类型的未处理异常
附加信息: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);
我的班级:
[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 和一些其他基本类型,我一直在努力解决这个问题,但它就是不想工作。
编辑:
[ForeignKey(typeof(ParticipantIdentity))]
public int participantIdentitiesId { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<ParticipantIdentity> participantIdentities { get; set; }
有错误:
SQLiteNetExtensions.dll 中出现“SQLiteNetExtensions.Exceptions.IncorrectRelationshipException”类型的未处理异常
附加信息:MatchDetail.participantIdentities:找不到 OneToMany 关系的外键