【发布时间】:2013-04-30 08:47:29
【问题描述】:
以下是我从 GameByGameTypes 和 Categories 中获取值时的代码,但在名为 GameByGameTypes 的表中,CategoryId 列的值为 NULL。所以我想要 0 代替 NULL
Category objCategory;
var query = (from gametypebygametype in db.GameByGameTypes.Where( x => x.GameTypeId == gametypeid)
join category in db.Categories
on gametypebygametype.CategoryId equals category.CategoryId into joined
from category in joined.DefaultIfEmpty()
select new
{
category.CategoryId ,
category.CategoryName
}
).Distinct();
List<Category> objlistCategory = new List<Category>();
foreach (var item_temp in query)
{
objCategory = new Category();
objCategory.CategoryId = item_temp.CategoryId;
objCategory.CategoryName = item_temp.CategoryName;
objlistCategory.Add(objCategory);
}
【问题讨论】:
标签: c# wpf asp.net-mvc linq