none
How should LINQ to SQL entities be decorated in order to give the desired information RRS feed

  • General discussion

  • In data base designing, some foreign keys or some coding fields (fields with a simple data indicating a much complex data) are embedded in tables. When it is consumed some information, which these fields are pointing to, are the target. in such situation, this entity class may decorated with other class which facilitate gathering the additional information. In the constructor, the LINQ to SQL entity object received and each item may be access via some properties. Since information gathered in the time of consuming and just items gathered which are needed, it supports the deterring feature of LINQ. One of the usage of these decorated entities is in binding grid objects. I have brought the code snippet  of two decorated entity classes bellow. Please tell me what do you think about them and what should I do in order to improve it.

    (Quiz_Test test and Quiz_Choice are the LINQ to SQL entity object)


    namespace GraphicalObjects
    {
        public class TestGO
        {
            #region Constructors
            /// <summary>
            /// Main Constructor.
            /// </summary>
            /// <param name="test">The original test entity object.</param>
            public TestGO(Quiz_Test test)
            {
                Test = test;
            }
            #endregion
            #region Properties
            public string BaseBranchLessonName
            {
                get { return (Test == null) ? string.Empty : BaseBranchLessonBs.GetName(Test.Quiz_BaseBranchLessonId); }
            }
            public string Hardship
            {
                get { return (Test == null) ? string.Empty : BusinessBs.GetNameByParentNameAndCode<BaseCoding, Coding>("Hardship", Test.Hardship); }
            }
            public long Id
            {
                get { return (Test == null) ? 0 : Test.AutoCode; }
            }
            public string QuestionText
            {
                get
                {
                    if (Test == null)
                        return string.Empty;
                    if (Test.Quiz_TestText == null)
                    {
                        if (Test.Quiz_TestItems != null)
                            if (Test.Quiz_TestItems.Count > 0)
                                return Test.Quiz_TestItems[0].QuestionText;
                    }
                    else
                        return Test.Quiz_TestText.Name;
                    return string.Empty;
                }
            }
            public string SeasonName
            {
                get { return (Test == null) ? string.Empty : (Test.Quiz_SeasonId == null) ? string.Empty : BusinessBs.GetById<Quiz_Season>(Test.Quiz_SeasonId.Value).Name; }
            }
            public string Text
            {
                get
                {
                    if (Test == null)
                        return string.Empty;
                    if (Test.Quiz_TestText != null)
                        return Test.Quiz_TestText.Text;
                    return string.Empty;
                }
            }
            public string Type
            {
                get { return (Test == null) ? string.Empty : BusinessBs.GetNameByParentNameAndCode<BaseCoding, Coding>("TestingType", Test.Type); }
            }
            public double Weight
            {
                get { return (Test == null) ? 0 : Test.Weight; }
            }
            /// <summary>
            /// The original test entity object.
            /// </summary>
            public Quiz_Test Test { get; protected set; }
            #endregion
        }
    }

    namespace GraphicalObjects
    {
        public class ChoiceGO
        {
            #region Constructors
            /// <summary>
            /// Main constructor.
            /// </summary>
            /// <param name="choice">The original choice entity object.</param>
            public ChoiceGO(Quiz_Choice choice)
            {
                Choice = choice;
            }
            #endregion
            #region Properties
            public int ChoiceNo
            {
                get { return (Choice == null) ? 0 : (int)Choice.ChoiceNo; }
            }
            public long Id
            {
                get { return (Choice == null) ? 0 : Choice.AutoCode; }
            }
            public long ImageId
            {
                get { return (Choice == null) ? 0 : (Choice.ImageId.HasValue) ? 0 : Choice.ImageId.Value; }
            }
            public string IsTheAnswer
            {
                get { return (Choice == null) ? string.Empty : Choice.IsTheAnswer ? "*" : string.Empty; }
            }
            public long ParentId
            {
                get { return (Choice == null) ? 0 : Choice.ParentId; }
            }
            public string Text
            {
                get { return (Choice == null) ? string.Empty : Choice.Text; }
            }
            /// <summary>
            /// The original choice entity object.
            /// </summary>
            public Quiz_Choice Choice { get; protected set; }
            #endregion
        }
    }

    Thursday, August 27, 2009 11:06 AM