I have the following model:
public class FactCache
{
public int ID { get; set; }
public DateTime MonthDate { get; set; }
public string AttributeKey { get; set; }
public decimal RawValue { get; set; }
public decimal ManDayValue { get; set; }
public decimal FTEValue { get; set; }
public int? InputResourceID { get; set; }
public int? PhaseID { get; set; }
public virtual InputResources InputResource { get; set; }
public virtual DimPhase Phase { get; set; }
}
As you can see above, InputResourceID
and PhaseID
are nullable optional fields.
I want to write a query to find the first entry for a given date and AttributeKey
where both PhaseID
and InputResourceID
are null.
I have tried the following code:
FactCache fact = db.FactCache.FirstOrDefault(
a => a.InputResourceID == null
&& a.PhaseID == null
&& a.MonthDate == monthDate
&& a.AttributeKey == key);
However, it returns a null object. What is the correct way to write the above query?
I have checked the database and there are indeed entries with null PhaseID
and InputResourceID
.