【发布时间】:2011-12-01 22:38:24
【问题描述】:
我正在遍历父记录(“欧洲”)并使用其子记录更新其名为“childPublication”的<Ienumerable> 字段。但是 childPublication 在循环和赋值之后是 null 吗?
这是我的代码:
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 的代码中结束了吗?