本文整理汇总了C#中System.Linq.Expressions.Expression.Nullify方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Nullify方法的具体用法?C# Expression.Nullify怎么用?C# Expression.Nullify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.Nullify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NotEqualNullable
public static Expression NotEqualNullable(Expression e1, Expression e2)
{
if (e1.Type.IsNullable() == e2.Type.IsNullable())
return Expression.NotEqual(e1, e2);
return Expression.NotEqual(e1.Nullify(), e2.Nullify());
}
示例2: EqualNullable
public static Expression EqualNullable(Expression e1, Expression e2)
{
if (e1 == NewId || e2 == NewId)
return False;
if (e1.Type.IsNullable() == e2.Type.IsNullable())
return Expression.Equal(e1, e2);
return Expression.Equal(e1.Nullify(), e2.Nullify());
}
示例3: ParameterFactory
public override MemberInitExpression ParameterFactory(Expression parameterName, SqlDbType sqlType, string udtTypeName, bool nullable, Expression value)
{
Expression valueExpr = Expression.Convert(IsDate(sqlType) ? Expression.Call(miAsserDateTime, value.Nullify()) : value, typeof(object));
if (nullable)
valueExpr = Expression.Condition(Expression.Equal(value, Expression.Constant(null, value.Type)),
Expression.Constant(DBNull.Value, typeof(object)),
valueExpr);
NewExpression newExpr = Expression.New(typeof(SqlParameter).GetConstructor(new[] { typeof(string), typeof(object) }), parameterName, valueExpr);
List<MemberBinding> mb = new List<MemberBinding>()
{
Expression.Bind(typeof(SqlParameter).GetProperty("IsNullable"), Expression.Constant(nullable)),
Expression.Bind(typeof(SqlParameter).GetProperty("SqlDbType"), Expression.Constant(sqlType)),
};
if (sqlType == SqlDbType.Udt)
mb.Add(Expression.Bind(typeof(SqlParameter).GetProperty("UdtTypeName"), Expression.Constant(udtTypeName)));
return Expression.MemberInit(newExpr, mb);
}
示例4: GetCompareExpression
public static Expression GetCompareExpression(FilterOperation operation, Expression left, Expression right, bool inMemory = false)
{
switch (operation)
{
case FilterOperation.EqualTo: return Expression.Equal(left, right);
case FilterOperation.DistinctTo:
{
var t = left.Type.UnNullify();
var mi = t.IsValueType ? miDistinctNullable : miDistinct;
return Expression.Call(mi.MakeGenericMethod(t), left.Nullify(), right.Nullify());
}
case FilterOperation.GreaterThan: return Expression.GreaterThan(left, right);
case FilterOperation.GreaterThanOrEqual: return Expression.GreaterThanOrEqual(left, right);
case FilterOperation.LessThan: return Expression.LessThan(left, right);
case FilterOperation.LessThanOrEqual: return Expression.LessThanOrEqual(left, right);
case FilterOperation.Contains: return Expression.Call(Fix(left, inMemory), miContains, right);
case FilterOperation.StartsWith: return Expression.Call(Fix(left, inMemory), miStartsWith, right);
case FilterOperation.EndsWith: return Expression.Call(Fix(left, inMemory), miEndsWith, right);
case FilterOperation.Like: return Expression.Call(miLike, Fix(left, inMemory), right);
case FilterOperation.NotContains: return Expression.Not(Expression.Call(Fix(left, inMemory), miContains, right));
case FilterOperation.NotStartsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miStartsWith, right));
case FilterOperation.NotEndsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miEndsWith, right));
case FilterOperation.NotLike: return Expression.Not(Expression.Call(miLike, Fix(left, inMemory), right));
default:
throw new InvalidOperationException("Unknown operation {0}".Formato(operation));
}
}
示例5: ParameterFactory
public override MemberInitExpression ParameterFactory(Expression parameterName, SqlDbType sqlType, string udtTypeName, bool nullable, Expression value)
{
Expression valueExpr = Expression.Convert(IsDate(sqlType) ? Expression.Call(miAsserDateTime, value.Nullify()) : value, typeof(object));
if (nullable)
valueExpr = Expression.Condition(Expression.Equal(value, Expression.Constant(null, value.Type)),
Expression.Constant(DBNull.Value, typeof(object)),
valueExpr);
NewExpression newExpr = Expression.New(typeof(SqlCeParameter).GetConstructor(new[] { typeof(string), typeof(object) }), parameterName, valueExpr);
List<MemberBinding> mb = new List<MemberBinding>()
{
Expression.Bind(typeof(SqlCeParameter).GetProperty("IsNullable"), Expression.Constant(nullable)),
Expression.Bind(typeof(SqlCeParameter).GetProperty("SqlDbType"), Expression.Constant(sqlType)),
};
if (sqlType == SqlDbType.Udt)
throw new InvalidOperationException("User Defined Tyeps not supported on SQL Server Compact ({0})".FormatWith(udtTypeName));
return Expression.MemberInit(newExpr, mb);
}
示例6: EqualNullableGroupBy
public static Expression EqualNullableGroupBy(Expression e1, Expression e2)
{
return Expression.Or(Expression.Equal(e1.Nullify(), e2.Nullify()),
Expression.And(new IsNullExpression(e1), new IsNullExpression(e2)));
}