关于数据模型Model构架研究

在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,还有什么高招啊...郁闷中...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值