locked
Generic Lookup Class RRS feed

  • Question

  • User-574293449 posted

    hi,

      I am designing my entity for my web application. I have a lookup table for Designation, Country etc. How i create entities for this concept and how i code in DAL layer..

    I got th following article related to this

    http://forums.asp.net/t/1273449.aspx/2/10

    From there i got a nice solution. But i have the confusion is as per the thread we need to create seperate entity for eah item in the look up and created Generic class in DAL. But in the future if i need one more entry in the lookup master what i do? I need to add one mor entity and handle the code in all layers othe than DAL?

    Wednesday, September 12, 2012 8:59 AM

Answers

  • User-576912550 posted

    In the code side also you can create entity/class which represent your back end table as follow.

    public class CodeLookUp
    {
        public int LookUpID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int? ParentLookUpID { get; set; }
    }

    Once above class list is populated with table rows, we can easily filter it with .Where based on ParentLookUpID value.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 12:31 AM

All replies

  • User-576912550 posted

    General practice for lookup entity is to store it in common table rather than creating separate table for Designation, country, etc. Create general table as below.

    LookUpID

    Name

    Description

    ParentLookUpID

    1

    Country

    Country

    NULL

    2

    India

    India

    1

    3

    US

    US

    1

    4

    Designation

    Designation

    NULL

    5

    Manager

    Manager

    4

    6

    Engineer

    Engineer

    4

    7

    UK

    UK

    1

    Once you adopt such generic table design, then after you can create generic DAL, entity based on it.

    Tuesday, November 20, 2012 12:45 PM
  • User-574293449 posted

    hi friend,

      Yea in the back end side i am ok. My confusion is in the business entity side only. Even if table is generic, in the entity side i created seperate entity for each type. So if i have one more entry in the lookup in future howe i handle. Again i add one more entity? or any better approach is there?

    Monday, December 3, 2012 12:17 AM
  • User-576912550 posted

    In the code side also you can create entity/class which represent your back end table as follow.

    public class CodeLookUp
    {
        public int LookUpID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int? ParentLookUpID { get; set; }
    }

    Once above class list is populated with table rows, we can easily filter it with .Where based on ParentLookUpID value.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2012 12:31 AM
  • User-574293449 posted

    thanks. This is good idea. Sorry i am not debating but need to know the better solution. As per technical this is ok and is easy for extenstention. But as per business functionality is it ok? I mean i read that business entities are based on business and create seperate entit for each business objects. Kindly give advise on this. Sorry if i am going in wrong way

    Tuesday, December 4, 2012 1:15 AM
  • User-576912550 posted

    I mean i read that business entities are based on business and create seperate entit for each business objects.

    Akhil, I do agree with you that separate entity for business object... but when you are using any ER model concept in your OO application, generally at that time our business entity represent our DB object i.e. Table, View, etc. and in case of generic lookup, i think this pattern is widely adopted in many application. I cant recall any name right now but I have seen this pattern used in many application i worked till. I think in DNN(dotNetNuke) also they are following such table structure. (I am not sure about DNN's recent version, but i think they are using. Again I am not sure about DNN)

    Wednesday, December 12, 2012 1:49 AM
  • User-574293449 posted

    thanks friend thanks foir the clarification

    Thursday, December 13, 2012 11:42 PM