private void ProcessSelectableConditionalConstrainSelector(ConditionalConstrainSelector expression, bool isSubQuery, Func <string, string> createVariableName, StrongEntityAccessor mainEntityAccessor)
        {
            if (!isSubQuery)
            {
                if (mainEntityAccessor != null)
                {
                    _currentStrongEntityAccessorVisitDelegate = entityAccessor =>
                    {
                        if (_metaGraphVariableName == null)
                        {
                            _commandText.AppendFormat("?G{0}", entityAccessor.About.Name);
                        }
                        else
                        {
                            _commandText.Append("IF(ISBLANK(");
                            VisitComponent(entityAccessor.About);
                            _commandText.Append("),");
                            VisitComponent(mainEntityAccessor.About);
                            _commandText.Append(",");
                            VisitComponent(entityAccessor.About);
                            _commandText.AppendFormat(") AS ?{0} ?{1}", _ownerVariableName, _entityVariableName);
                        }
                    };

                    _ownerVariableName = "entity";
                }

                _commandText.Append("DISTINCT ");
                int index = 0;
                foreach (IExpression selectable in ((ISelectableQueryComponent)expression).Expressions)
                {
                    switch (index)
                    {
                    case 0:
                        _subjectVariableName = (selectable is Alias ? ((Alias)selectable).Name.Name : (selectable is Identifier ? ((Identifier)selectable).Name : null));
                        break;

                    case 1:
                        _predicateVariableName = (selectable is Alias ? ((Alias)selectable).Name.Name : (selectable is Identifier ? ((Identifier)selectable).Name : null));
                        break;

                    case 2:
                        _objectVariableName = (selectable is Alias ? ((Alias)selectable).Name.Name : (selectable is Identifier ? ((Identifier)selectable).Name : null));
                        break;
                    }

                    index++;
                }
            }
        }
        private void OverrideEntitySelector(Identifier identifier)
        {
            StrongEntityAccessor entityAccessor = _query.FindAllComponents <StrongEntityAccessor>().Where(item => item.About == identifier).FirstOrDefault();

            if (entityAccessor == null)
            {
                entityAccessor = new StrongEntityAccessor(identifier);
                _query.Elements.Add(entityAccessor);
            }

            if ((entityAccessor.UnboundGraphName == null) || (entityAccessor.UnboundGraphName == entityAccessor.About))
            {
                entityAccessor.UnboundGraphName = (from accessor in _query.FindAllComponents <StrongEntityAccessor>()
                                                   from constrain in accessor.Elements.OfType <EntityConstrain>()
                                                   where (constrain.Value is Identifier) && ((Identifier)constrain.Value == identifier)
                                                   select accessor.About).FirstOrDefault() ?? identifier;
                UnboundConstrain genericConstrain = new UnboundConstrain()
                {
                    Subject = new Identifier(identifier.Name + "_s"), Predicate = new Identifier(identifier.Name + "_p"), Value = new Identifier(identifier.Name + "_o")
                };
                entityAccessor.Elements.Add(genericConstrain);
                UnboundConstrain targetConstrain = new UnboundConstrain()
                {
                    Subject = identifier, Predicate = new Identifier(identifier.Name + "p"), Value = new Identifier(identifier.Name + "o")
                };
                entityAccessor.Elements.Add(targetConstrain);
                _query.Select.Clear();
                if (_mainFromComponent.Elements[0] is UnboundConstrain)
                {
                    ConditionalConstrainSelector selector = new ConditionalConstrainSelector(entityAccessor, genericConstrain, (UnboundConstrain)_mainFromComponent.Elements[0]);
                    _query.Select.Add(selector);
                }

                _query.Select.Add(entityAccessor);
            }
        }