我需要知道如何将int转换为可以为null的int.但是,我不断收到错误"没有为类型'System.Nullable`1 [System.Int32]'和'System.Int32'定义二进制运算符Equal." 任何解决方案 它需要是Microsoft SQL Server的可空int类型.
somevalue = Expression.Constant(something.GetValue(some,null).To<Nullable<System.Int32>> ());
public static T To<T>(this object obj)
{
Type t = typeof(T);
Type u = Nullable.GetUnderlyingType(t);
if (u != null)
{
if (obj == null)
return default(T);
return (T)Convert.ChangeType(obj, u);
}
else
{
return (T)Convert.ChangeType(obj, t);
}
}'
Run Code Online (Sandbox Code Playgroud)