我有一个 RavenDB 文档的以下结构
{
"RpcTechDataCollectionModel": {
"Weekend": "March 16 - 17, 2013",
"ServiceTitle": "Some Title",
"Notes": "",
"WeekendServices": [{
"ServiceTime": "",
"SiteName": "Bowridge",
"SoundOperator": "Rob",
"WorshipLeader": "Daryl",
"Notes": "",
"Songs": [{
"SongName": "Foo",
"MinSpl": "86",
"MaxSpl": "92",
"Note": ""
}, {
"SongName": "Bar",
"MinSpl": "89",
"MaxSpl": "96",
"Note": ""
}]
}, {
"ServiceTime": "",
"SiteName": "Bearspaw",
"SoundOperator": "Peter",
"WorshipLeader": "Tim",
"Notes": "",
"Songs": [{
"SongName": "Das",
"MinSpl": "86",
"MaxSpl": "91",
"Note": ""
}, {
"SongName": "Bar",
"MinSpl": "87",
"MaxSpl": "99",
"Note": ""
}]
}]
}
}
现在我正在尝试为此建立一个模型,但我想知道构建它的最佳方法是什么。注意,没有子对象WeekendService
或Song
将在父对象之外使用RpcTechCollectionModel
选项一是
namespace MyProject.Models {
using System.Collections.Generic;
public class RpcTechDataCollectionModel{
RpcTechDataCollectionModel(){
this.WeekendServices = new List<WeekendService>();
}
public string Weekend { get; set; }
public string ServiceTitle { get; set; }
public string Notes { get; set; }
public List<WeekendService> WeekendServices { get; set; }
public class WeekendService{
WeekendService(){
this.SongRecords = new List<SongRecord>();
}
public DateTime ServiceTime { get; set; }
public string SiteName { get; set; }
public string SoundOperator { get; set; }
public string WorshipLeader { get; set; }
public string Notes { get; set; }
public List<Song> Songs { get; set; }
public class Song {
public string SongName { get; set; }
public double MinSpl { get; set; }
public double MaxMax { get; set; }
public string Note { get; set; }
}
}
}
}
我更喜欢这个,因为它既漂亮又干净,而且易于理解。问题在于它在技术上违反了“每个文件一个类”规则
选项二
public class RpcTechDataCollectionModel{
RpcTechDataCollectionModel(){
this.WeekendServices = new List<WeekendService>();
}
public string Weekend { get; set; }
public string ServiceTitle { get; set; }
public string Notes { get; set; }
public List<WeekendService> WeekendServices { get; set; }
}
public class WeekendService{
WeekendService(){
this.SongRecords = new List<SongRecord>();
}
public DateTime ServiceTime { get; set; }
public string SiteName { get; set; }
public string SoundOperator { get; set; }
public string WorshipLeader { get; set; }
public string Notes { get; set; }
public List<Song> Songs { get; set; }
}
public class Song {
public string SongName { get; set; }
public double MinSpl { get; set; }
public double MaxMax { get; set; }
public string Note { get; set; }
}
这并不违反该规则,但似乎有点痛苦。
以一种或另一种方式做这件事的利弊是什么,一种被认为是“正确/首选”的方式,还是在这种情况下它更“让你的船浮起来”?