我在数据库表中有一个Nullable
BIGINT
字段。
我正在使用linq
到sql
来检索c#中该表的数据。
c.ExtensionID ==(ExtensionId == 0?(long?)null:ExtensionId)
上面的代码是我目前正在使用的代码,但它不会返回ExtensionID
列中带有null的行。
但如果我像c.ExtensionID == null
那样使用它,那么它将返回记录。
以下是完整的linq to sql代码。
var q = (from c in dbContext.Investments
join cd in dbContext.ContractContractorDetails
on c.ContractContractorId equals cd.ID
join cc in dbContext.ContractorCategories
on c.ContractorCategory equals cc.ID
join ic in dbContext.InvestmentCategories
on c.InvestmentCategory equals ic.ID
where c.InvestmentClassificationType == type && cd.ContractId.Equals(ContractID) && c.Phase == phase && c.ExtensionID == (ExtensionId == 0 ? (long?)null : ExtensionId)
select new
{
ID = c.ID,
Year = c.Year,
ContractorCategory = c.ContractorCategory,
ContractorCategoryName = cc.Name,
CompanyName = c.CompanyName,
InvestmentCategory = c.InvestmentCategory,
InvestmentCategoryName = ic.Name,
Summary = c.Summary,
IsContractRelated = c.IsContractRelated,
InvestmentAmount = c.InvestmentAmount,
Phase = c.Phase,
InvestmentClassificationType = c.InvestmentClassificationType,
ContractContractorId = c.ContractContractorId,
CreatedBy = c.CreatedBy,
LastUpdatedOn = c.LastUpdatedOn,
LastUpdatedBy = c.LastUpdatedBy,
Period=c.Period,
ExtensionId = c.ExtensionID
}).ToList();
答案 0 :(得分:0)