如何:在 sqlite-net-extensions 中执行嵌套列表
找到答案:将问题作为如何执行的示例。
我遇到的问题与 sqlite-net-extensions 无关,但我将问题保留在上下文中。
[老问题]
TwinCoders SQLite-net 扩展有问题。
我正在尝试将 Series 对象插入到我的数据库中:
我正在使用该Db.InsertWithChildren(SelectedSeriesObject,recursive:true)
方法。
Series 对象与它的属性相应地添加。
所有剧集也都添加了,那里没有问题。
问题是BaseSeason。
它只会插入一个 Season 对象,它(由于某种原因)是 Series 中 Seasons 列表的最后一个 Season 对象
public class BaseSeries : BaseMedia
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Indexed]
public int ShowId { get; set; }
public string FirstAirDate { get; set; }
public string LastAirDate { get; set; }
public string Status { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BaseSeason> Seasons { get; set; }
/// <summary>
/// TvShow = 0, Anime = 1
/// </summary>
public int SeriesType { get; set; }
}
public class BaseSeason
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(BaseSeries))]
public int SeasonId { get; set; }
public int SeasonNumber { get; set; }
public int NumberOfEpisodes { get; set; }
public string Plot { get; set; }
public string Poster { get; set; }
public string AirDate { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<BaseEpisode> Episodes { get; set; }
[ManyToOne]
public BaseSeries BaseSeries { get; set; }
}
public class BaseEpisode
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(BaseSeason))]
public int EpisodeId { get; set; }
public string Title { get; set; }
public string Plot { get; set; }
public string Poster { get; set; } //still path
public string AirDate { get; set; }
public int EpisodeNumber { get; set; }
public int SeasonNumber { get; set; }
public string SeriesName { get; set; }
[ManyToOne]
public BaseSeason BaseSeason { get; set; }
}
有没有人对 sqlite-net-extensions 中的嵌套关系有经验,知道如何进行这项工作或看看我做错了什么?