/// <summary>
/// 获得置顶数据
/// </summary>
private IList<HaierPageView> getSetTopData()
{
IHSetTopService stservice = CastleContext.Instance.GetService<IHSetTopService>();
IList<int> setTopIdList = stservice.FindAllSetTopIdByCustomWhere(" AND [status]=1 AND [endDate]>=GETDATE()");
if (setTopIdList.Count < 1)
{
return new List<HaierPageView>();
}
string tempTopIds = "";
foreach (int item in setTopIdList)
{
tempTopIds += tempTopIds == "" ? item.ToString() : "," + item.ToString();
}
string temp = string.Format(@" AND Page_ID in ({0})",tempTopIds);
IHaierPageViewService pservice = CastleContext.Instance.GetService<IHaierPageViewService>();
Hashtable htSetTopquery = new Hashtable();
htSetTopquery.Add("HaierTagViewWhere", temp);
htSetTopquery.Add("HaierPageViewWhere", "");
return pservice.FindAllByCustomWhere(htSetTopquery);
}
return null 与return new List<HaierPageView>()的区别
IList<HaierPageView> tempTopLists = (List<HaierPageView>)(getSetTopData());
foreach (var item in tempTopLists)
{
result.Add(item);
}
如果您return null的话上面的foreach就会报没有实例化的异常
但是您return new List<HaierPageView>()就不会的。
希望这个经验对大家有用。