コード例 #1
0
ファイル: LinqEngine.cs プロジェクト: radtek/vita
        // Note: command expected to be analyzed already
        public SqlStatement Translate(LinqCommand command)
        {
            // pre-process; special commands do not produce lambda when command is created - only SqlCacheKey so that SQL
            // is looked up in cache and we do not need anything else; building actual query lambda is encoded in setup Action,
            // which we invoke here;
            // also dynamic linq queries postpone rewrite (changing locals to parameters) until late time
            switch (command)
            {
            case SpecialLinqCommand specCmd:
                specCmd.SetupAction?.Invoke(specCmd);
                break;

            case DynamicLinqCommand dynCmd:
                if (command.Lambda == null)
                {
                    LinqCommandRewriter.RewriteToLambda(dynCmd);
                }
                break;
            } //switch

            try {
                switch (command.Operation)
                {
                case LinqOperation.Select:
                    return(TranslateSelect(command));

                case LinqOperation.Update:
                case LinqOperation.Delete:
                case LinqOperation.Insert:
                default:
                    return(TranslateNonQuery((DynamicLinqCommand)command));
                } //switch
            } catch (LinqTranslationException) {
                throw; // if it is already Linq translation exception, pass it up.
            } catch (Exception ex) {
                var message = "Linq to SQL translation failed, invalid expression: " + ex.Message;
                throw new LinqTranslationException(message, command, ex);
            }
        }
コード例 #2
0
        public static void RewriteToLambda(DynamicLinqCommand command)
        {
            var rewriter = new LinqCommandRewriter();

            rewriter.RewriteCommand(command);
        }