I m not sure how to explain this, so I m gonna show you some code first and explain what it does.
Extension Filter
: receives a parameter expression and a special type of filter I ve built for my application (IFilter
).
public static IQueryable<TSource> Filter<TSource, TProperty>(this IQueryable<TSource> source, Expression<Func<TSource, TProperty>> expression, IFilter f)
{
if (!f.IsEmpty())
{
string propertyName = ExpressionHelper.GetExpressionText(expression);
source = source.Where(f.GetWhereLambda<TSource>(propertyName));
}
return source;
}
目前,有可能这样做(简化!)
var Foo = db.Foos
.Select(e => new
{
ID = e.ID, // Primary key.
Bar = e.BarID // Some nullable FK.
})
.Filter(e => e.Bar, this.someSpecialFilter);
因此,那里存在问题。 BarID
可能是无效的,因此,欧洲自由贸易联盟正在使用<代码>int?制作一个PPOCO级,这对我来说是罚款的,但对于我的言论处理却不然。 这个问题首先源于:。 • 如何从类型变量中产生一种可变的加固;T>?。
问题描述:
The exception The binary operator Equal is not defined for the types System.Nullable`1[System.Int32] and System.Int32 . is throwed from this code:
return Expression.Equal(leftExpr, rightExpr);
离开 Expr is a System.Nullable1[System.]. Int32
(作为<代码>int?)和右翼为System。 Int32
(the Value, as Int32').
问题:
我能做些什么来避免? from int?
? 我指的是,能否避免获得一种无效的类型,或者我是否在守则中对此加以核对?
感谢很多人,
Ricardo