开发者

LINQ2SQL A problem with return items based on a parameter

I occured a strange problem. I have that method

public static void ProcessCategories(int? myID)
{
  var tmpList = Adapter.Category.Where(x => x.IdParentCategory == myID).ToList();
}

when myID == null开发者_如何学Go (the parameter), the tmpList doesn't contain any elements, but if I type

x.IdParentCategory == null then some items are returned. Why ?


Try this:

public static void ProcessCategories(int? myID)
{
  var tmpList = Adapter.Category.Where(x => x.IdParentCategory == myID || (myID == null && x.IdParentCategory == null)).ToList();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜