Example #1
0
        private static void TranslateGraphNode(
            IncludeNode graphNode, IModelInfoProvider infoProvider, IDbObjectFactory dbFactory,
            UniqueNameGenerator nameGenerator, AbstractMethodTranslator[] addons)
        {
            //TODO: check if there is a chain in the relation and throw exceptions

            var fromSelect = graphNode.FromNode?.Select;

            var state = new TranslationState();

            if (fromSelect != null)
            {
                state.ResultStack.Push(graphNode.FromNode.Select);
            }

            var translator = new ExpressionTranslator(infoProvider, dbFactory, state, addons);

            // translated current included node
            translator.Visit(graphNode.Expression);

            var dbObject = translator.GetElement();
            var dbRef    = dbObject as DbReference;

            var includedSelect = dbRef != null?dbFactory.BuildSelect(dbRef) : (IDbSelect)dbObject;

            includedSelect = SqlSelectOptimizer.Optimize(includedSelect);

            // if from node is not null, then we need to add the forgien key into the selection
            // of the temp table, and make the new select join to the translated select
            if (graphNode.FromNode != null)
            {
                UpdateFromNodeTempTable(graphNode.FromNode, dbObject, includedSelect, dbFactory, nameGenerator);
            }

            // if the graph node has child node, we need to create temp table for current node
            // so that the child nodes can join to the temp table containing forgien keys
            if (graphNode.ToNodes.Any())
            {
                UpdateIncludeSelectAndProcessToNodes(graphNode, includedSelect, infoProvider, dbFactory, nameGenerator, addons);
            }
            else
            {
                graphNode.Select = includedSelect;
            }

            var returnType = graphNode.Expression.GetReturnBaseType();

            graphNode.Select = DbColumnToEntityPropertyMapper.Map(graphNode.Select, returnType, infoProvider, dbFactory, nameGenerator);

            // update fill function
            if (graphNode.FromNode != null)
            {
                graphNode.FillFunc = FillFunctionMaker.Make(graphNode, infoProvider);
            }

            graphNode.Graph.ScriptToNodes[graphNode.Select] = graphNode;
        }
Example #2
0
        internal bool TranslateMethodCall(
            MethodCallExpression m, TranslationState state, UniqueNameGenerator nameGenerator)
        {
            var method = m.Method;

            if (!_methodTranslators.ContainsKey(method.Name))
            {
                return(false);
            }

            var translator = _methodTranslators[method.Name];

            translator.Translate(m, state, nameGenerator);
            return(true);
        }
Example #3
0
        public ExpressionTranslator(
            IModelInfoProvider infoProvider, IDbObjectFactory dbFactory,
            TranslationState state = null, IEnumerable <AbstractMethodTranslator> methodTranslators = null)
        {
            _infoProvider = infoProvider;
            _dbFactory    = dbFactory;
            _state        = state ?? new TranslationState();

            RegisterDefaultPlugIns();

            if (methodTranslators == null)
            {
                return;
            }

            foreach (var translator in methodTranslators)
            {
                translator.Register(_plugIns);
            }
        }