I have a Nullable BIGINT field in the database table.
I am using linq to sql to retrieve data from that table in c#.
c.ExtensionID == (ExtensionId == 0 ? (long?)null : ExtensionId)
The above piece of code is what i am using currently, but it does not return me the rows with null in ExtensionID Column.
but if i use it like c.ExtensionID == null then it will return records.
Below is the full linq to sql code.
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();
ExtensionIdis never0. Do you checkExtensionId =0?ExtensionID=null?c.ExtensionID == (ExtensionId == 0 ? null : ExtensionId)?