关于数据模型Model构架研究

来源:互联网 发布:淘宝如何查看类目排名 编辑:程序博客网 时间:2024/06/06 05:41

在MVC的结构模型中,数据实体类是很重要的结构之一,也就是数据实体类Data.而数据模型中还有其他类,如业务逻辑类BLL、数据访问类DAL、还有数据集类DataSet。
这4个类一般情况下,是一个数据库表对应一组"类",也就是说,一个数据库表对应一个Data类,一个DataSet类,一个DAL类,BLL类。
下面我将遇到的问题和优化方案归纳如下:
在fotosay项目中,在开发过程中,为了满足需求,改变了数据库表,所以相应的模型就要改变,为了不影响以前开发的代码,于是新建了多个数据实体类Data和数据集类DataSet。譬如PhotoBasicData、PhotoBasicData1,PhotoBasicData2...。 PhotoBasicDataSet,PhotoBasicDataSet1,PhotoBasicDataSet2...这样一个数据表就有了多个模型,给程序带来了较大的冗余,而且不容易维护和修改,代码呈现散乱。
解法1、在项目中有出现,就是利用"继承",代码虽然有减少,但是没有优化到最好!

using System;

namespace Fotosay.Model
{
    [Serializable]

    public class SystemRecordData2 : SystemRecordData
    {
        public SystemRecordData2()
        {
        }
        public SystemRecordData2(int recordID, int forumsID, string shortTitle, string recordTitle, int recordType, int commendUserID, int objectID, string picUrl, int userID, string userName, string nickName, int sort, int systemColumnID, string navigateUrl, DateTime createDate)
            :base(recordID, forumsID, shortTitle, recordTitle, recordType, commendUserID, objectID, picUrl, userID, userName, nickName)
        {
            this.sort = sort;
            this.systemColumnID = systemColumnID;
            this.navigateUrl = navigateUrl;
            this.createDate = createDate;
        }
    }
}


解法2、利用方法的"重载",可以既不改动以前的代码,又可以让程序达到最优化.
而且保证了代码的整洁完美,实现了一个数据库表对应一个Data类,一个DataSet类,一个DAL类,BLL类。

using System;

namespace Fotosay.Model
{
    [Serializable]

    public class SystemRecordData
    {
        public SystemRecordData()
        {
        }
        public SystemRecordData(int recordID, int forumsID, string shortTitle, string recordTitle, int recordType, int commendUserID, int objectID, string picUrl, int userID, string userName, string nickName)
        {
            this.recordID = recordID;
            this.forumsID = forumsID;
            this.shortTitle = shortTitle;
            this.recordTitle = recordTitle;
            this.recordType = recordType;
            this.commendUserID = commendUserID;
            this.objectID = objectID;
            this.picUrl = picUrl;
            this.userID = userID;
            this.userName = userName;
            this.nickName = nickName;
        }
        public SystemRecordData(int recordID, int forumsID, string shortTitle, string recordTitle, int recordType, int commendUserID, int objectID, string picUrl, int userID, string userName, string nickName, int sort, int systemColumnID, string navigateUrl, DateTime createDate)
        {
            this.recordID = recordID;
            this.forumsID = forumsID;
            this.shortTitle = shortTitle;
            this.recordTitle = recordTitle;
            this.recordType = recordType;
            this.commendUserID = commendUserID;
            this.objectID = objectID;
            this.picUrl = picUrl;
            this.userID = userID;
            this.userName = userName;
            this.nickName = nickName;
            this.sort = sort;
            this.systemColumnID = systemColumnID;
            this.navigateUrl = navigateUrl;
            this.createDate = createDate;
        }
    }
}

又待解决问题:如果链表查询的话怎么保证Model代码的整洁统一和高效啊?
可能解决方案:用“解法1”,还是没达到perfect,还有什么高招啊...郁闷中...

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 两个月的宝宝不爱吃奶怎么办 仓鼠走路画圈了怎么办 力气大但扳手腕不行怎么办 只睡了两个小时怎么办 微博账号被冻结了怎么办 微博一天多次解冻怎么办 肿瘤对化疗不敏感怎么办 2个月宝宝肺炎怎么办 小孩咳嗽2个月怎么办 两个月的小孩子气管炎怎么办? 小孩子两个月发烧38度怎么办 两个月的小孩子咳嗽怎么办 5个月宝宝吃奶少怎么办 26岁的1型糖尿病怎么办 睡前吃得太饱怎么办 胰岛素2小时>300怎么办 血清c肽测定高怎么办 体测蛋白质和骨骼肌偏高怎么办 半个月重了十斤怎么办 月经停了2个月怎么办 在练腹肌中腹痛怎么办 越练肌肉越肥怎么办 喘不过气来 心闷怎么办 被气得喘不过气怎么办 健身完头晕想吐怎么办 吃多了反胃头晕怎么办 合同未约定退货货物积压怎么办 运动内衣把胸压平怎么办 经常穿皮鞋脚臭怎么办 买衣服胸围小了怎么办 内衣下胸围太紧怎么办 穿文胸衣服要开怎么办 运动内衣的拉链老来怎么办 胸罩没干急着穿怎么办 跑步时大腿很痒怎么办 胖大腿内侧磨伤怎么办 内衣围带过松怎么办 内衣底围特别紧怎么办 全棉衣服上的油怎么办 高腰牛仔裤腰大了怎么办 新买衣服太硬怎么办