2012-06-06 240 views
0
public class CellValue 
{ 
    double? Max; 
    double? Min; 
    string Value; 
    string Annotation; 
} 

    public T GetOne(Expression<Func<T, bool>> predicate) 
{ 
    IQueryable<T> query = this.context.Set<T>(); 
    return query.FirstOrDefault(predicate); 
} 

    public class Steel: CellValue{} 

    CellValue cell = new CellValue{Max = 0.8, Min = 0.1, Value="test"}; 
    Steel steel = service.GetOne(t=>t.Max == cell.Max && t.Min == cell.Min && t.Value ==cell.Value && t.Annotation == cell.Annotation); 
    //but the object steel is always null. Jush Why? 

我檢查了我的數據庫,但我不知道它總是null.Expression樹和Lambda表達式可能是問題。爲什麼在調用方法IQueryable.FirstOrDefault()時總是返回null?

回答

1

對於引用類型或值類型的默認值(例如,int是值類型,所以它將返回0),「OrDefault」方法返回null。

+0

我確定它是引用類型。 – user1439889

相關問題