本文整理汇总了C#中DbExpressionKind类的典型用法代码示例。如果您正苦于以下问题:C# DbExpressionKind类的具体用法?C# DbExpressionKind怎么用?C# DbExpressionKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbExpressionKind类属于命名空间,在下文中一共展示了DbExpressionKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbUnaryExpression
internal DbUnaryExpression(DbExpressionKind kind, TypeUsage resultType, DbExpression argument)
: base(kind, resultType)
{
Debug.Assert(argument != null, "DbUnaryExpression.Argument cannot be null");
_argument = argument;
}
示例2: CreateComparison
private Expression CreateComparison(Expression left, Expression right, DbExpressionKind kind)
{
if (left.Type == typeof(string) && right.Type == typeof(string))
{
return CreateStringComparison(left, right, kind);
}
switch (kind)
{
case DbExpressionKind.Equals:
return Expression.Equal(left, right);
case DbExpressionKind.NotEquals:
return Expression.NotEqual(left, right);
case DbExpressionKind.GreaterThan:
return Expression.GreaterThan(left, right);
case DbExpressionKind.GreaterThanOrEquals:
return Expression.GreaterThanOrEqual(left, right);
case DbExpressionKind.LessThan:
return Expression.LessThan(left, right);
case DbExpressionKind.LessThanOrEquals:
return Expression.LessThanOrEqual(left, right);
default:
throw new InvalidOperationException(
"The ExpressionKind cannot be " + kind.ToString());
}
}
示例3: GetLeafNodes
// <summary>
// Uses a stack to non-recursively traverse a given tree structure and retrieve the leaf nodes.
// </summary>
// <param name="root"> The node that represents the root of the tree. </param>
// <param name="kind"> Expressions not of this kind are considered leaves. </param>
// <param name="getChildNodes">
// A function that traverses the tree by retrieving the <b>immediate</b> descendants of a (non-leaf) node.
// </param>
// <returns> An enumerable containing the leaf nodes. </returns>
public static IEnumerable<DbExpression> GetLeafNodes(
this DbExpression root,
DbExpressionKind kind,
Func<DbExpression, IEnumerable<DbExpression>> getChildNodes)
{
DebugCheck.NotNull(getChildNodes);
var nodes = new Stack<DbExpression>();
nodes.Push(root);
while (nodes.Count > 0)
{
var current = nodes.Pop();
if (current.ExpressionKind != kind)
{
yield return current;
}
else
{
foreach (var node in getChildNodes(current).Reverse())
{
nodes.Push(node);
}
}
}
}
示例4: CreateMockExpression
private static Mock<DbExpression> CreateMockExpression(DbExpressionKind kind)
{
var mockRoot = new Mock<DbExpression>();
mockRoot.Setup(m => m.ExpressionKind).Returns(kind);
return mockRoot;
}
示例5: DbUnaryExpression
internal DbUnaryExpression(DbExpressionKind kind, TypeUsage resultType, DbExpression argument)
: base(kind, resultType)
{
DebugCheck.NotNull(argument);
_argument = argument;
}
示例6: DbBinaryExpression
internal DbBinaryExpression(DbExpressionKind kind, TypeUsage type, DbExpression left, DbExpression right)
: base(kind, type)
{
DebugCheck.NotNull(left);
DebugCheck.NotNull(right);
_left = left;
_right = right;
}
示例7: DbBinaryExpression
internal DbBinaryExpression(DbExpressionKind kind, TypeUsage type, DbExpression left, DbExpression right)
: base(kind, type)
{
Debug.Assert(left != null, "DbBinaryExpression.Left cannot be null");
Debug.Assert(right != null, "DbBinaryExpression.Right cannot be null");
_left = left;
_right = right;
}
示例8: CreateStringComparison
private Expression CreateStringComparison(Expression left, Expression right, DbExpressionKind kind)
{
var method = Expression.Call(null, StringFunctions.CompareTo, left, right);
var mode = GetCompareMode(kind);
Expression res = Expression.Equal(method, Expression.Constant(mode.Item1));
if (!mode.Item2)
{
res = Expression.Not(res);
}
return res;
}
示例9: FlattenAssociativeExpression
/// <summary>
/// Creates a flat list of the associative arguments.
/// For example, for ((A1 + (A2 - A3)) + A4) it will create A1, (A2 - A3), A4
/// Only 'unfolds' the given arguments that are of the given expression kind.
/// </summary>
/// <param name="expressionKind"></param>
/// <param name="arguments"></param>
/// <returns></returns>
internal static IEnumerable<DbExpression> FlattenAssociativeExpression(
DbExpressionKind expressionKind, params DbExpression[] arguments)
{
if (!_associativeExpressionKinds.Contains(expressionKind))
{
return arguments;
}
var outputArguments = new List<DbExpression>();
foreach (var argument in arguments)
{
ExtractAssociativeArguments(expressionKind, outputArguments, argument);
}
return outputArguments;
}
示例10: ExtractAssociativeArguments
/// <summary>
/// Helper method for FlattenAssociativeExpression.
/// Creates a flat list of the associative arguments and appends to the given argument list.
/// For example, for ((A1 + (A2 - A3)) + A4) it will add A1, (A2 - A3), A4 to the list.
/// Only 'unfolds' the given expression if it is of the given expression kind.
/// </summary>
/// <param name="expressionKind"></param>
/// <param name="argumentList"></param>
/// <param name="expression"></param>
private static void ExtractAssociativeArguments(
DbExpressionKind expressionKind, List<DbExpression> argumentList, DbExpression expression)
{
if (expression.ExpressionKind != expressionKind)
{
argumentList.Add(expression);
return;
}
//All associative expressions are binary, thus we must be dealing with a DbBinaryExpresson or
// a DbArithmeticExpression with 2 arguments.
var binaryExpression = expression as DbBinaryExpression;
if (binaryExpression != null)
{
ExtractAssociativeArguments(expressionKind, argumentList, binaryExpression.Left);
ExtractAssociativeArguments(expressionKind, argumentList, binaryExpression.Right);
return;
}
var arithExpression = (DbArithmeticExpression)expression;
ExtractAssociativeArguments(expressionKind, argumentList, arithExpression.Arguments[0]);
ExtractAssociativeArguments(expressionKind, argumentList, arithExpression.Arguments[1]);
}
示例11: MatchKind
/// <summary>
/// Constructs a new pattern that will match an expression with the specified <see cref="DbExpressionKind"/>.
/// </summary>
internal static Func<DbExpression, bool> MatchKind(DbExpressionKind kindToMatch)
{
return (e => e.ExpressionKind == kindToMatch);
}
示例12: IsCompatible
public bool IsCompatible(DbExpressionKind expressionKind)
{
switch (expressionKind)
{
case DbExpressionKind.Filter:
return Where == null && Columns.Count == 0;
case DbExpressionKind.Project:
return Columns.Count == 0;
case DbExpressionKind.Limit:
return Limit == null;
case DbExpressionKind.Skip:
return Skip == null;
case DbExpressionKind.Sort:
return Columns.Count == 0 &&
GroupBy == null &&
OrderBy == null;
case DbExpressionKind.GroupBy:
return Columns.Count == 0 &&
GroupBy == null &&
OrderBy == null &&
Limit == null;
}
throw new InvalidOperationException();
}
示例13: VisitExprKind
private void VisitExprKind(DbExpressionKind kind)
{
_key.Append('[');
_key.Append(_exprKindNames[(int)kind]);
_key.Append(']');
}
示例14: TransformIntersectOrExcept
/// <summary>
/// This method is used for translating <see cref="DbIntersectExpression"/> and <see cref="DbExceptExpression"/>,
/// and for translating the "Except" part of <see cref="DbSkipExpression"/>.
/// into the follwoing expression:
///
/// A INTERSECT B, A EXCEPT B
///
/// (DISTINCT)
/// |
/// FILTER
/// |
/// | - Input: A
/// | - Predicate:(NOT)
/// |
/// ANY
/// |
/// | - Input: B
/// | - Predicate: (B.b1 = A.a1 or (B.b1 is null and A.a1 is null))
/// AND (B.b2 = A.a2 or (B.b2 is null and A.a2 is null))
/// AND ...
/// AND (B.bn = A.an or (B.bn is null and A.an is null)))
///
/// Here, A corresponds to right and B to left.
/// (NOT) is present when transforming Except
/// for the purpose of translating <see cref="DbExceptExpression"/> or <see cref="DbSkipExpression"/>.
/// (DISTINCT) is present when transforming for the purpose of translating
/// <see cref="DbExceptExpression"/> or <see cref="DbIntersectExpression"/>.
///
/// For <see cref="DbSkipExpression"/>, the input to ANY is caped with project which projects out only
/// the columns represented in the sortExpressionsOverLeft list and only these are used in the predicate.
/// This is because we want to support skip over input with non-equal comarable columns and we have no way to recognize these.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <param name="expressionKind"></param>
/// <param name="sortExpressionsOverLeft">note that this list gets destroyed by this method</param>
/// <param name="sortExpressionsBindingVariableName"></param>
/// <returns></returns>
private DbExpression TransformIntersectOrExcept(
DbExpression left, DbExpression right, DbExpressionKind expressionKind, IList<DbPropertyExpression> sortExpressionsOverLeft,
string sortExpressionsBindingVariableName)
{
var negate = (expressionKind == DbExpressionKind.Except) || (expressionKind == DbExpressionKind.Skip);
var distinct = (expressionKind == DbExpressionKind.Except) || (expressionKind == DbExpressionKind.Intersect);
var leftInputBinding = left.Bind();
var rightInputBinding = right.Bind();
IList<DbPropertyExpression> leftFlattenedProperties = new List<DbPropertyExpression>();
IList<DbPropertyExpression> rightFlattenedProperties = new List<DbPropertyExpression>();
FlattenProperties(leftInputBinding.Variable, leftFlattenedProperties);
FlattenProperties(rightInputBinding.Variable, rightFlattenedProperties);
//For Skip, we need to ignore any columns that are not in the original sort list. We can recognize these by comparing the left flattened properties and
// the properties in the list sortExpressionsOverLeft
// If any such columns exist, we need to add an additional project, to keep the rest of the columns from being projected, as if any among these
// are non equal comparable, SQL Server 2000 throws.
if (expressionKind == DbExpressionKind.Skip)
{
if (RemoveNonSortProperties(
leftFlattenedProperties, rightFlattenedProperties, sortExpressionsOverLeft, leftInputBinding.VariableName,
sortExpressionsBindingVariableName))
{
rightInputBinding = CapWithProject(rightInputBinding, rightFlattenedProperties);
}
}
Debug.Assert(
leftFlattenedProperties.Count == rightFlattenedProperties.Count,
"The left and the right input to INTERSECT or EXCEPT have a different number of properties");
Debug.Assert(leftFlattenedProperties.Count != 0, "The inputs to INTERSECT or EXCEPT have no properties");
//Build the predicate for the quantifier:
// (B.b1 = A.a1 or (B.b1 is null and A.a1 is null))
// AND (B.b2 = A.a2 or (B.b2 is null and A.a2 is null))
// AND ...
// AND (B.bn = A.an or (B.bn is null and A.an is null)))
DbExpression existsPredicate = null;
for (var i = 0; i < leftFlattenedProperties.Count; i++)
{
//A.ai == B.bi
DbExpression equalsExpression = leftFlattenedProperties[i].Equal(rightFlattenedProperties[i]);
//A.ai is null AND B.bi is null
DbExpression leftIsNullExpression = leftFlattenedProperties[i].IsNull();
DbExpression rightIsNullExpression = rightFlattenedProperties[i].IsNull();
DbExpression bothNullExpression = leftIsNullExpression.And(rightIsNullExpression);
DbExpression orExpression = equalsExpression.Or(bothNullExpression);
if (i == 0)
{
existsPredicate = orExpression;
}
else
{
existsPredicate = existsPredicate.And(orExpression);
}
//.........这里部分代码省略.........
示例15: CreateMockArgumentExpression
private static Mock<DbPropertyExpression> CreateMockArgumentExpression(DbExpressionKind kind)
{
var mockLeftExpression = new Mock<DbPropertyExpression>();
mockLeftExpression.Setup(m => m.ExpressionKind).Returns(kind);
return mockLeftExpression;
}