zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

CYQ.Data 轻量数据访问层(三) 构造数据单元(下)

数据 访问 Data 构造 轻量 单元 CYQ
2023-09-11 14:20:55 时间

继上一节,回头看这张图片:

回顾上节的话题,怎么设计这样一个数据单元类?才不会有重复的单元表头,又能合理解释出数据与表头的关系?

经过长久的深思后。。一个关键的字出来了"ref",引用,是的,用的这就个,如果每个单元格,都包括值和单元表头,而单元表头,都引用同一个的时候,就刚好满足了需求。

 

 

于是,我们开始写出这样的类:

先构造出一个存放值的类:

复制代码 ExpandedBlockStart.gif ///  summary
    /// 只包函被填充的数据状态和值
    ///  /summary
    public class MDataCellValue
    {
        ///  summary
        /// //值是否为空
        ///  /summary
        internal bool _IsNull;
        ///  summary
        /// 值是否被改变了
        ///  /summary
        internal bool _IsChange;
        ///  summary
        /// 值是多少
        ///  /summary
        internal object _Value;

        public MDataCellValue()
        {
            _IsNull = true;
            _IsChange = false;
            _Value = null;
        }
    }

接着,我们构造存放表头:

我们可以参考数据库,也可以参考DataCell中的数据结构,构造出以下的类:

复制代码 ExpandedBlockStart.gif   ///  summary
    /// 只包函数据库字段的属性
    ///  /summary
    public class MDataCellStruct
    {
        internal bool _IsCanNull;
        internal bool _IsReadOnly;
        internal string _ColumnName;
        internal System.Data.SqlDbType _SqlType;
        internal int _MaxSize;
        internal string _Operator = "=";
        internal ParameterDirection _ParaDirection;

        #region 构造函数
        public MDataCellStruct(string ColumnName, System.Data.SqlDbType SqlType, bool IsReadOnly, bool IsCanNull, int MaxSize, ParameterDirection paraDirection)
        {
            _ColumnName = ColumnName;
            _SqlType = SqlType;
            _IsReadOnly = IsReadOnly;
            _IsCanNull = IsCanNull;
            _MaxSize = MaxSize;
            _ParaDirection = paraDirection;
        }

        #endregion

        #region 属性
        ///  summary
        /// 数据字段列名称
        ///  /summary
        public string ColumnName
        {
            get
            {
                return this._ColumnName;
            }

        }

        ///  summary
        /// 数据类型
        ///  /summary
        public System.Data.SqlDbType SqlType
        {
            get
            {
                return this._SqlType;
            }
        }

        ///  summary
        /// 数据字段列是否为只读
        ///  /summary
        public bool IsReadOnly
        {
            get
            {
                return this._IsReadOnly;
            }
        }

        ///  summary
        /// 数据字段列长度大小
        ///  /summary
        public int MaxSize
        {
            get
            {
                return this._MaxSize;
            }
        }

        ///  summary
        /// 数据字段列值是否能为空
        ///  /summary
        public bool IsCanNull
        {
            get
            {
                return this._IsCanNull;
            }
        }
        ///  summary
        /// 存储过程时用的参数
        ///  /summary
        public ParameterDirection ParaDirection
        {
            get
            {
                return this._ParaDirection;
            }
            set
            {
                _ParaDirection = (ParameterDirection)value;
            }
        }
        public string Operator
        {
            get
            {
                return _Operator;
            }
            set
            {
                _Operator = value;
            }
        }
        #endregion


    }
1.NetDh框架之数据库操作层--Dapper简单封装,可支持多库实例、多种数据库类型等(附源码和示例代码) 1.NetDh框架开始的需求场景 需求场景: 1.之前公司有不同.net项目组,有的项目是用SqlServer做数据库,有的项目是用Oracle,后面也有可能会用到Mysql等,而且要考虑后续扩展成主从库、多库的需求。