标题: 关于实体模型 [讨论贴]
- 丁一 2007-12-20 10:56 阅读:133
- 评论:0 | 添加评论
首先,我是个菜鸟,如果在某些问题上存在误区还请大家指正.

其次,请大家不要因为问题幼稚而笑话我.. [图片]


场景:

现数据库中有2个表(见图),

一个问题表(Question)和一个问题树表(QuestionTree).

问题表为基础数据表,用来提供数据以构造问题树.(问题可以被多个不同版本的树重用)

问题树表为问题关系记录表,用来记录不同版本(VersionNumber字段区分)的问题树.

(典型的树结构,父子问题关联. 在此不多说这个了)

[图片]

问题:

现在要将这种关系映射成实体模型,

我和一同事在映射成实体模型时存在一些不同的见解,

按他的想法映射成的实体模型如下(想法A):

Question.cs

public class Question
{
    private Guid _questionId;
    public Guid QuestionId
    {get{return this._questionId;}
         set{this._questionId = value;}}


    private string _questionInfo;
    public string QuestionInfo
    {get{return this._questionInfo;}
         set{this._questionInfo = value;}}


    private IList<QuestionTree> _questionTrees;
    public IList<QuestionTree> QuestionTrees
    {
        get{ if(this._questionTrees == null)
                this._questionTrees = new List<QuestionTree>();
                return this._questionTrees;}
        set{ this._questionTrees = value; }
}
}


QuestionTree.cs (当获取树时返回该对象)

 

public class QuestionTree
{
    private Guid _questionTreeId;
    public Geid QuestionTreeId
    {
            get{return this._questionTreeId;}
            set{this._questionTreeId = value;}
        }


        private Question _parentQuestion;
        // 当前节点的父节点
         public Question ParentQuestion
        {
        get{return this._parentQuestion;}
        set{this._parentQuestion = value;}
        }


        private Question _childQuestion;
        // 当前节点
         public Question ChildQuestion
        {
        get{return this._childQuestion;}
        set{this._childQuestion = value;}
        }


        private int _versionNumber;
        public int VersionNumber
        {
        get{return this._versionNumber;}
        set{this._versionNumber = value;}
        }
}



他这样映射的理由是能更好的体现QuestionTree 是用来处理树关系的,在类使用者眼里这个关系是”显性”的.

但我反而觉得,这种映射对类使用者来说概念更加混乱了,同时也带来了大量数据冗余.(如图)

[图片]
(图中只做了下一级树节点, 以后的以此类推)


按我的想法映射成的实体模型如下(想法B):

Question.cs (当获取树时返回该对象)

 

public class Question
{
    private Guid _questionId;
    public Guid QuestionId
        {
       get{return this._questionId;}
           set{this._questionId = value;}
        }


        private string _questionInfo;
    public string QuestionInfo
    {
           get{return this._questionInfo;}
           set{this._questionInfo = value;}
        }


    private IList<Question> _childQuestions;
    public IList<Question> ChildQuestions
    {
            get{ 
                  if(this._childQuestions == null)
                     this._childQuestions = new List<Question>();
                  return this._childQuestions;}

            set{ this._childQuestions = value; }
        }
}


我的理由是这样映射实体模型概念要清晰的多,同时数据也不会产生冗余.(如图)

他觉得这种映射把QuestionTree 的意义给”隐性”了,类使用者不能了解到后台逻辑.

[图片]
(图中只做了下一级树节点, 以后的以此类推)

 

希望大家在此指出 想法A 和 想法B 的优缺点或毛病,
到底哪种想法更可取,
同时也希望大家能给出自己的意见或想法.
本菜鸟在此先谢了..



添加评论
返回顶部 | 返回首页