【发布时间】:2016-03-21 03:24:22
【问题描述】:
如何:在 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 中的嵌套关系有经验,知道如何进行这项工作或看看我做错了什么?
【问题讨论】:
标签: c# sqlite sqlite-net-extensions