开发者

LINQ2SQL A problem with return items based on a parameter

开发者 https://www.devze.com 2023-01-25 14:51 出处:网络
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();

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

精彩评论

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