public virtual void AddMember(MemberNode member, int memberIndex, string format = null) { Ensure.That(memberIndex, "memberIndex").IsGte(0); var memberPart = string.IsNullOrEmpty(format) ? GetMemberNodeString(member, memberIndex) : string.Format(format, GetMemberNodeString(member, memberIndex)); if (!HasWrittenMember) { State.AppendFormat("({0}{1}{2})", memberPart, OpMarker, ValueMarker); HasWrittenMember = true; return; } //TODO: Perhaps AddMemberAsValue if (!HasWrittenValue) //When using member as value, eg. Where Name = SecondName { State = State.Replace(ValueMarker, memberPart); HasWrittenValue = true; } }
protected virtual string GetMemberNodeString(MemberNode member, int memberIndex) { const string memFormat = "mem{0}.[{1}]"; var shouldUseExplicitStringValue = member is IStringOperationMemberNode && member.DataTypeCode.IsValueType(); return shouldUseExplicitStringValue ? string.Format(memFormat, memberIndex, IndexStorageSchema.Fields.StringValue.Name) : string.Format(memFormat, memberIndex, IndexStorageSchema.Fields.Value.Name); }
public static ToUpperMemberNode ToUpperNode(this MemberNode memberNode) { return(new ToUpperMemberNode(memberNode.Path, memberNode.DataType, memberNode.DataTypeCode)); }
private MemberNode CreateNewMemberNode(MemberExpression e) { var graphLine = new List<MemberExpression> {e}; if (IsFlatteningMembers) graphLine.InsertRange(0, _virtualPrefixMembers.Reverse().Where(vir => !graphLine.Any(gl => gl.Equals(vir)))); if (graphLine.Count < 1) return null; MemberNode previousNode = null; for (var c = 0; c < graphLine.Count; c++) { var memberExpression = graphLine[c]; var isLast = c == (graphLine.Count - 1); var path = previousNode == null ? memberExpression.ToPath() : string.Format("{0}.{1}", previousNode.Path, memberExpression.ToPath()); if (isLast && memberExpression.Type.IsEnumerableType()) previousNode = new MemberNode(path, memberExpression.Type.GetEnumerableElementType()); else previousNode = new MemberNode(path, memberExpression.Type); } if (previousNode != null) { if (e.Type.IsNullablePrimitiveType()) return new NullableMemberNode(previousNode.Path, e.Type); if (e.Expression.Type.IsNullablePrimitiveType()) return new NullableMemberNode(previousNode.Path, e.Expression.Type); } return previousNode; }
public static StringExactMemberNode ToStringExactNode(this MemberNode memberNode, string value) { return(new StringExactMemberNode(memberNode.Path, memberNode.DataType, memberNode.DataTypeCode, value)); }
public static StringStartsWithMemberNode ToStringStartsWithNode(this MemberNode memberNode, string value) { return(new StringStartsWithMemberNode(memberNode.Path, memberNode.DataType, memberNode.DataTypeCode, value)); }
public static LikeMemberNode ToLikeNode(this MemberNode memberNode, string value) { return(new LikeMemberNode(memberNode.Path, memberNode.DataType, memberNode.DataTypeCode, value)); }
public static NotInSetMemberNode ToNotInSetNode(this MemberNode memberNode, IEnumerable values) { return(new NotInSetMemberNode(memberNode.Path, memberNode.DataType, memberNode.DataTypeCode, values.Yield().ToArray())); }
protected virtual void OnProcessWhereMemberNode(IParsedLambda lambda, SqlExpression expression, ISqlWhereCriteriaBuilder builder, int nodeIndex, MemberNode memberNode) { var memberIndex = expression.GetExistingOrNewMemberIndexFor(memberNode.Path); if (!expression.ContainsWhereMemberFor(memberNode.Path)) expression.AddWhereMember(new SqlWhereMember( memberIndex, memberNode.Path, memberNode.DataType, memberNode.DataTypeCode)); if (memberNode is InSetMemberNode) { OnProcessWhereInSetMemberNode(builder, (InSetMemberNode)memberNode, memberIndex); return; } if (memberNode is LikeMemberNode) { OnProcessWhereLikeMemberNode(builder, (LikeMemberNode)memberNode, memberIndex); return; } if (memberNode is StringContainsMemberNode) { OnProcessWhereStringContainsMemberNode(builder, (StringContainsMemberNode)memberNode, memberIndex); return; } if (memberNode is StringExactMemberNode) { OnProcessWhereStringExactMemberNode(builder, (StringExactMemberNode)memberNode, memberIndex); return; } if (memberNode is StringEndsWithMemberNode) { OnProcessWhereStringEndsWithMemberNode(builder, (StringEndsWithMemberNode)memberNode, memberIndex); return; } if(memberNode is StringStartsWithMemberNode) { OnProccessWhereStringStartsWithMemberNode(builder, (StringStartsWithMemberNode)memberNode, memberIndex); return; } if(memberNode is ToLowerMemberNode) { OnProccessWhereToLowerMemberNode(builder, (ToLowerMemberNode)memberNode, memberIndex); return; } if (memberNode is ToUpperMemberNode) { OnProccessWhereToUpperMemberNode(builder, (ToUpperMemberNode)memberNode, memberIndex); return; } if (memberNode.DataType.IsAnyBoolType()) { var leftNode = lambda.Nodes.PeekLeft(nodeIndex); var rightNode = lambda.Nodes.PeekRight(nodeIndex); var isImplicitBoolNode = !(leftNode is OperatorNode) && !(rightNode is OperatorNode); if (isImplicitBoolNode) { OnProcessWhereImplicitBoolMemberNode(builder, memberNode, memberIndex); return; } } builder.AddMember(memberNode, memberIndex); }
protected virtual void OnProcessWhereImplicitBoolMemberNode(ISqlWhereCriteriaBuilder builder, MemberNode memberNode, int memberIndex) { builder.AddMember(memberNode, memberIndex); builder.AddOp(new OperatorNode(Operator.Equal())); builder.AddValue(new ValueNode(true)); }
protected virtual MemberNode CreateNewMemberNode(MemberExpression e) { var graphLine = new List<MemberExpression>(); if (IsFlatteningMembers) { graphLine.AddRange(VirtualPrefixMembers); if (!graphLine.Last().Equals(e)) graphLine.Add(e); } else graphLine.Add(e); MemberNode previousNode = null; for (var c = 0; c < graphLine.Count; c++) { var memberExpression = graphLine[c]; var isLast = c == (graphLine.Count - 1); var path = previousNode == null ? memberExpression.ToPath() : string.Format("{0}.{1}", previousNode.Path, memberExpression.ToPath()); if (isLast && memberExpression.Type.IsEnumerableType()) { var elementType = memberExpression.Type.GetEnumerableElementType(); previousNode = new MemberNode(path, elementType, DataTypeConverter.Convert(elementType, path)); } else previousNode = new MemberNode(path, memberExpression.Type, DataTypeConverter.Convert(memberExpression.Type, path)); } if (previousNode != null) { if (e.Type.IsNullablePrimitiveType()) return new NullableMemberNode(previousNode.Path, e.Type, DataTypeConverter.Convert(e.Type, previousNode.Path)); if (e.Expression.Type.IsNullablePrimitiveType()) return new NullableMemberNode(previousNode.Path, e.Expression.Type, DataTypeConverter.Convert(e.Expression.Type, previousNode.Path)); } return previousNode; }