Click here to Skip to main content
15,896,154 members
Articles / Web Development / HTML

Database Object Model

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
21 Feb 2012CPOL2 min read 25.9K   693   11  
A Sample ORM project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DBOMSqlSharp
{
    public class SqlUnary : SqlExpression
    {
        SqlExpression expression;

        protected SqlUnary()
            : base()
        {
        }
        protected SqlUnary(SqlExpression expression)
            : this()
        {
            this.expression = expression;
        }

        public override object Clone()
        {
            SqlUnary unary = (SqlUnary)this.MemberwiseClone();
            return unary;
        }
        public override bool Equals(BaseSqlObject other)
        {
            bool b = base.Equals(other);
            SqlUnary o = (SqlUnary)other;
            return b
                && SqlComparer.EqualObjects(this.Expression, o.Expression);
        }

        public SqlExpression Expression
        {
            get
            {
                return this.expression;
            }
        }

        public virtual string Operator
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public override List<SqlParameter> SqlParameters
        {
        	get
        	{
                return BaseSqlObject.SqlParametersOf(this.Expression);
        	}
        }
        public override SqlTreeNode SqlNode
        {
            get
            {
                SqlTreeNode n = new SqlTreeNode(null, this);
                this.Nodes.Add(n);
                n.AddChild(this.Expression.SqlNode);
                return n;
            }
        }
        public override string SqlString
        {
            get
            {
                this.OnSqlStringIn(this, EventArgs.Empty);
                string s = this.Operator + this.Expression.SqlString;
                this.OnSqlStringOut(this, EventArgs.Empty);
                return s;
            }
        }
        public override string HtmlString
        {
            get
            {
                return "";
            }
        }
    }

    public class SqlPositive : SqlUnary
    {
        public SqlPositive(SqlExpression expression)
            : base(expression)
        {
        }

        public override string Operator
        {
            get
            {
                return "+";
            }
        }
    }

    public class SqlNegative : SqlUnary
    {
        public SqlNegative(SqlExpression expression)
            : base(expression)
        {
        }

        public override string Operator
        {
            get
            {
                return "-";
            }
        }
    }

    public class SqlBitNot : SqlUnary
    {
        public SqlBitNot(SqlExpression expression)
            : base(expression)
        {
        }

        public override string Operator
        {
            get
            {
                return "~";
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions