2012-06-06 246 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

相关问题