File: ExpressionTranslator.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (61 lines) | stat: -rwxr-xr-x 2,217 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
´╗┐using System;
using System.Linq.Expressions;

namespace DbLinq.Data.Linq.Sugar.Expressions
{
    /// <summary>
    ///  Permits translation of expressions for specific database vendors
    /// </summary>
    /// <remarks>
    ///  <para>
    ///   Not all databases are equal, and some databases have SQL constraints 
    ///   that are not shared by others.  Some of these SQL dialect constraints
    ///   can be handled by <see cref="DbLinq.Vendor.ISqlProvider" />, but
    ///   in some circumstances that's too late in the game.
    ///  </para>
    ///  <para>
    ///   Case in point: for 
    ///   <c>(from p in people orderby p.LastName select p).Count()</c>
    ///   is translated into e.g. 
    ///   <c>SELECT COUNT(*) FROM People ORDER BY LastName</c>.  However, this 
    ///   is invalid for Microsoft SQL Server (the <c>ORDER BY</c> cannot be
    ///   present), and by the time <c>ISqlProvider</c> is being used, there's
    ///   no easy way to remove the OrderBy sequence.
    ///  </para>
    ///  <para>
    ///   The <c>ExpressionTranslator</c> type allows vendor code to manipulate
    ///   the expression tree <i>before</i> SQL generation, thus allowing 
    ///   otherwise invalid expressions to be removed prior to the generation 
    ///   phase.
    ///  </para>
    /// </remarks>
#if !MONO_STRICT
    public
#endif
    class ExpressionTranslator
    {
        /// <summary>
        ///  Translate the entire (outermost) expression.
        /// </summary>
        /// <param name="e">
        ///  A <see cref="SelectExpression" /> containing the expression to 
        ///  translate.
        /// </param>
        /// <returns>
        ///  The <see cref="SelectExpression" /> to use for SQL generation.
        /// </returns>
        /// <remarks>
        ///  <para>
        ///   Derived classes can override this method to manipulate the 
        ///   entire expression prior to SQL generation.
        ///  </para>
        ///  <para>
        ///   The default implementation returns <c>e</c> unchanged.
        ///  </para>
        /// </remarks>
        public virtual SelectExpression OuterExpression(SelectExpression e)
        {
            return e;
        }
    }
}