分享自己做的一个简单的查询表达式模拟(ESQL,Linq)(2)

下面是几个特殊化的表达式类:
4)常量表达式:

 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)实体表信息表达式:

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)实体字段信息表达式:

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)别名表达式

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;
            }
        }
    }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值