我正在循環瀏覽父記錄(「歐洲」)並更新其名爲「子出版物」的字段及其子記錄。但是子版本在循環和賦值之後爲空?循環(IEnumerable)結果和更新,但沒有更新?
這裏是我的代碼:
foreach (var e in europe)
{
string child = e.HasChild ?? "";
if (child.Contains("True"))
{
IEnumerable<Publication> eChildrens = children.OfType<Publication>()
.Where(ep => ep.ParentID.Equals(e.PublicationId));
if (eChildrens.Count() > 0)
{
e.ChildPublication = eChildrens;
}
}
}
member.EuropeMiddleEastAfricaPublication = europe;
public class Publication
{
public int PublicationId { get; set; }
public int ContentTypeId { get; set; }
public string PublicationName { get; set; }
public string PublicationFullName { get; set; }
public string ShortDescription { get; set; }
public string LongDescription { get; set; }
public string URL { get; set; }
public string CountryId { get; set; }
public string LanguageId { get; set; }
public string Active { get; set; }
public string Subscription { get; set; }
public string ClientOnly { get; set; }
public string PrintVersion { get; set; }
public string EmailVersion { get; set; }
public string RegisteredforPrint { get; set; }
public string RegisteredforEmail { get; set; }
public int ParentID { get; set; }
public string HasChild { get; set; }
public IEnumerable<Publication> ChildPublication { get; set; }
}
您是否確認您至少在指派childPublication的代碼中最終生效? –