protected override ScalarExpression OnBuildQuery(QueryBuilderContext context) { if (ResultType.IsList) { throw new InvalidOperationException(); } var result = new LiteralExpression { Value = TypedValueHelper.FromDataType(ResultType.Type, Value) }; return(result); }
/// <summary> /// Returns a tree node that is representative of an entity or. /// </summary> /// <param name="context">Context information about this query building session, including the target structured query object.</param> /// <param name="allowReuse">A dedicated node should be returned because the caller intends on disturbing it.</param> /// <returns>A query node that can be used within the query.</returns> public override SQ.Entity OnBuildQueryNode(QueryBuilderContext context, bool allowReuse) { IEntity instance = Instance.Entity; long typeId = instance.TypeIds.First( ); if (context.ParentNode == null) { throw new Exception("No context."); } // Look for an existing relationship node in the tree that we can reuse SQ.CustomJoinNode result = !allowReuse ? null : context.ParentNode .RelatedEntities .OfType <SQ.CustomJoinNode>( ) .FirstOrDefault(cj => IsMatch(cj, Instance.Id) && cj.EntityTypeId.Id == typeId); // New node if (result == null) { result = new SQ.CustomJoinNode { EntityTypeId = typeId, JoinPredicateScript = "true" }; SQ.ScalarExpression predicate = new SQ.ComparisonExpression { Operator = SQ.ComparisonOperator.Equal, Expressions = { new SQ.IdExpression { NodeId = result.NodeId }, new SQ.LiteralExpression { Value = TypedValueHelper.FromDataType(ResultType.Type, Instance.Id) } } }; result.Conditions = new List <SQ.ScalarExpression> { predicate }; } context.ParentNode.RelatedEntities.Add(result); AddChildNodes(context, result, allowReuse); return(result); }