Я создаю базу данных с серверными классами как дочерние элементы других классов. Запись с внешними ключами работает отлично, однако, когда я пытаюсь получить данные обратно он выдает ошибку:Sqlite.net extions, Cant получить данные с GetWithChildren
An unhandled exception of type 'SQLiteNetExtensions.Exceptions.IncorrectRelationshipException' occurred in SQLiteNetExtensions.dll
Additional information: MatchDetail.timeline: At least one entity in a OneToOne relationship must have Foreign Key
Это мой код создания:
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 и некоторые другие базовые типы, я пытался это обработать, но он просто не хочет работать.
Заранее спасибо.
Edit:
[ForeignKey(typeof(ParticipantIdentity))]
public int participantIdentitiesId { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<ParticipantIdentity> participantIdentities { get; set; }
С ошибкой:
An unhandled exception of type 'SQLiteNetExtensions.Exceptions.IncorrectRelationshipException' occurred in SQLiteNetExtensions.dll
Additional information: MatchDetail.participantIdentities: Unable to find foreign key for OneToMany relationship
Спасибо за ответ, однако я не могу заставить списки работать, поскольку он не может найти и внешний ключ. [ForeignKey (typeof (ParticipantIdentity))] public int memberIdentitiesId {get; задавать; } [OneToMany (CascadeOperations = CascadeOperation.All)] public List <Участник_общества> УчастникиIdentities {get; задавать; } – Adib
У Whos был неправильный тип, но все равно получить ошибку. Он должен быть typeof (List) –
Adib
То же самое решение применяется, см. Мое редактирование. – redent84