我已经看过很多ObservableCollection<T>
二维物体的例子,但我正在处理一个多维物体。
Faith Life Church Daily Bible Reading API将在下面生成JSON数据(为简洁起见,这会缩短)......
{
"dailychapter": [{
"date": "2016-02-01",
"book": "Esther",
"chapter": 7,
"verses": [{
"number": 1,
"text": "So the king and Haman came to banquet with Esther the queen."
}, {
"number": 2,
"text": "And the king said again unto Esther on the second day at the banquet of wine, What is thy petition, queen Esther? and it shall be granted thee: and what is thy request? and it shall be performed, even to the half of the kingdom."
}]
}, {
"date": "2016-02-02",
"book": "Esther",
"chapter": 8,
"verses": [{
"number": 1,
"text": "On that day did the king Ahasuerus give the house of Haman the Jews' enemy unto Esther the queen. And Mordecai came before the king; for Esther had told what he was unto her."
}, {
"number": 2,
"text": "And the king took off his ring, which he had taken from Haman, and gave it unto Mordecai. And Esther set Mordecai over the house of Haman."
}]
}, {
"date": "2016-02-03",
"book": "Esther",
"chapter": 9,
"verses": [{
"number": 1,
"text": "Now in the twelfth month, that is, the month Adar, on the thirteenth day of the same, when the king's commandment and his decree drew near to be put in execution, in the day that the enemies of the Jews hoped to have power over them, (though it was turned to the contrary, that the Jews had rule over them that hated them;)"
}, {
"number": 2,
"text": "The Jews gathered themselves together in their cities throughout all the provinces of the king Ahasuerus, to lay hand on such as sought their hurt: and no man could withstand them; for the fear of them fell upon all people."
}]
}]
}
我有一个类,对于JSON,具有这种结构(由json2csharp生成的类)...
public class Verses
{
public int number { get; set; }
public string text { get; set; }
}
public class DailyChapter
{
public string date { get; set; }
public string book { get; set; }
public int chapter { get; set; }
public List<Verses> verses { get; set; }
}
public class RootObject
{
public List<DailyChapter> dailychapter { get; set; }
}
我在数据库方面有一定程度的背景,所以我最初的想法是使用ObservableCollection
作为平面数据库,就像这样......
date book chapter versenumber versetext
"2016-02-01" "Esther" 7 1 "So the king..."
"2016-02-01" "Esther" 7 2 "And the king..."
"2016-02-02" "Esther" 8 1 "On that day..."
"2016-02-02" "Esther" 8 2 "And the king..."
"2016-02-03" "Esther" 9 1 "Now in the..."
"2016-02-03" "Esther" 9 2 "The Jews gathered..."
我的ObservableCollection课程的结构是......
public class BibleReadingCollection
{
public string date { get; set; }
public string book { get; set; }
public int chapter { get; set; }
public int versenumber { get; set; }
public string versetext { get; set; }
public BibleReadingCollection(string _date, string _book, int _chapter, int _versenumber, string _versetext)
{
date = _date;
book = _book;
chapter = _chapter;
versenumber = _versenumber;
versetext = _versetext;
}
}
// create a collection (like an array) for the binding data to be added to
public static ObservableCollection<BibleReadingCollection> biblereadingcollection = new ObservableCollection<BibleReadingCollection>();
我的目的是使用此ObservableCollection以主/详细信息类型的方式提供我的应用程序的UI(主要是日期/章节,详细信息是一系列经文)。从理论上讲,主列表可以通过某种形式的LINQ语句填充,单击其中一章将触发另一个LINQ语句,该语句将用详细列表填充详细信息列表。
我的问题是,这是否是考虑ObservableCollections的正确方法(如平面数据库)。也许最好每天(并且因此每章)作为单个记录(行)并以某种方式将经文嵌套在该记录中。我不确定这是否可能(你可以在ObservableCollection中粘贴一个ObservableCollection或数组吗?)。我知道,在SQL-land中,您可以加入表格,这样您就不会复制这么多数据。然后,您可以创建一个输出看起来像平面数据库的查询。
你们觉得怎么样?我是一个非常业余的开发人员,所以很多这些概念对我来说都是新的。