程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 分享自己做的一個簡單的查詢表達式模擬(ESQL,Linq)(2)

分享自己做的一個簡單的查詢表達式模擬(ESQL,Linq)(2)

編輯:C#入門知識

下面是幾個特殊化的表達式類:
4)常量表達式:
[csharp]
public class ConstExp<T> : DbExpression 
   { 
       public string ParamName { get; private set; } 
       public T Value { get; private set; } 
       public ConstExp(T Value, string ParamName) 
           : base() 
       { 
           this.Parameters.Add(ParamName, new Parameter() { }); 
           this.Value = Value; 
           this.ParamName = ParamName; 
       } 
       public override string Expression 
       { 
           get 
           { 
               return ":"+this.ParamName; 
           } 
       } 
 
       public static ConstExp<T> C(string ParamName, T V) 
       { 
           return new ConstExp<T>(V, ParamName); 
       } 
   } 

5)實體表信息表達式:
[csharp]
public class TableInfo : IDbExpression 
    { 
        public string TableName{get;set;} 
        public string Expression 
        { 
            get {return TableName;} 
        } 
 
        public virtual Dictionary<string, Parameter> Parameters { get { return null; } } 
    } 
6)實體字段信息表達式:
[csharp]
public class FieldInfo : IDbExpression 
    { 
        public string FieldName{get;set;} 
        public string Expression 
        { 
            get { return FieldName; } 
        } 
        public virtual Dictionary<string, Parameter> Parameters { get { return null; } } 
 
       public static FieldInfo All 
        { 
            get 
            { 
                return new FieldInfo() { FieldName= "*" }; 
            } 
        } 
    } 

7)別名表達式
[csharp]
public class AliasExp : DbExpression 
    { 
        public AliasExp(string AliasName) 
        { 
            this.AliasName = AliasName; 
        } 
        public string AliasName { get;private set; } 
        public override string Expression 
        { 
            get 
            { 
                return "AliasName"; 
            } 
        } 
        public override Dictionary<string, Parameter> Parameters 
        { 
            get 
            { 
                return null; 
            } 
        } 
        public static readonly AliasExp T1; 
        public static readonly AliasExp T2; 
        public static readonly AliasExp T3; 
        public static readonly AliasExp T4; 
        public static readonly AliasExp T5; 
        public static readonly AliasExp T6; 
        public static readonly AliasExp T7; 
        public static readonly AliasExp T8; 
        public static readonly AliasExp T9; 
        public static readonly AliasExp A1; 
        public static readonly AliasExp A2; 
        public static readonly AliasExp A3; 
        public static readonly AliasExp A4; 
        public static readonly AliasExp A5; 
        public static readonly AliasExp A6; 
        static AliasExp() 
        { 
            T1 = new AliasExp("T1"); 
            T2 = new AliasExp("T2"); 
            T3 = new AliasExp("T3"); 
            T4 = new AliasExp("T4"); 
            T5 = new AliasExp("T5"); 
            T6 = new AliasExp("T6"); 
            T7 = new AliasExp("T7"); 
            T8 = new AliasExp("T8"); 
            T9 = new AliasExp("T9"); 
            A1 = new AliasExp("A1"); 
            A2 = new AliasExp("A2"); 
            A3 = new AliasExp("A3"); 
            A4 = new AliasExp("A4"); 
            A5 = new AliasExp("A5"); 
            A6 = new AliasExp("A6"); 
        } 
        public DbExpression this[FieldInfo e] 
        { 
            get 
            { 
                DbExpression theExp = new DbExpression(); 
                theExp.SQL.Append(this.AliasName + "." + e.Expression); 
                theExp.AddParams(e); 
                return theExp; 
            } 
        } 
        public DbExpression this[TableInfo e] 
        { 
            get 
            { 
                DbExpression theExp = new DbExpression(); 
                theExp.SQL.Append(e.Expression + " " + this.AliasName); 
                theExp.AddParams(e); 
                return theExp; 
            } 
        } 
        public DbExpression this[DbExpression e] 
        { 
            get 
            { 
                DbExpression theExp = new DbExpression(); 
                theExp.SQL.Append(e.Expression + " " + this.AliasName); 
                theExp.AddParams(e); 
                return theExp; 
            } 
        } 
    } 

摘自 hawksoft

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved