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であることがわかりません。式ツリーとラムダ式が問題である可能性があります。

4

1 に答える 1

1

「OrDefault」メソッドは、参照型の場合は null を返し、値型の場合はデフォルト値を返します (たとえば、int は値型であるため、0 を返します)。

于 2012-06-06T14:02:34.637 に答える