views:

100

answers:

9

Hi Experts,

I am working on a website where I have many lookup values like cities, states, countries car makes, models and many more. there are alwasy two fields for these values ID and Description. Now I have a question, should I keep them in one table and keep some TypeId kind of field which differentiate them or should they stay in differnt tables.

Also how would be my Dataprovider class, currently I am thinking to have one class which can provide all the data. But, I feel there will be many methods in this class.

Suggestions will be welcome.

Regards Parminder

A: 

I would prefer you putting them in separate tables for the ease of differentiation.

As for the dataprovider class is concerned, I recommend you using an ORM, instead of deciding how to write your dataprovider class.

Ngu Soon Hui
There are specific reasons to seperate them but there is also reason to keep them in a table with a type id. It really depends on what the poster is trying to accomplish. More info is needed before we can say that though.
JonH
A: 

Really depends, if you are selling products I would say yes keep them in one table and have some sort of TypeID to distinguish the type of product. For instance, if you are selling items your TypeID could be Automotive, Education, etc.

However, if you are dealing with different entities that serve a specific purpose and each entity doesn't really relate to one another then seperation is good. We need more info to help you :).

Dataprovider could be one class namely your data access layer, and it doesn't matter that you may have a lot of methods; that is quite normal.

JonH
A: 

cities, state, countries are seems to be different entities.

so its better to keep those details as seperate master table.

if there are any relation then relate them using foreign keys.

which will reduce the future overheads if there is going to be any change or updation and also to reduce the load to DB if these are all in one table.

Write a Seperate DBProvider to execute SP, adhoc queries

and also create seperate BusinessModel representing the each table which in terms interact with the DBProvider and the front end of the client.

That should be good and perfect design strategy.

solairaja
A: 

It depends on the scenario and domains for these entities. Lets say at design time if you are not aware of the type of entities you will be having then TypeId approach is better so that when a new type is added you don't have to create another entity for it. However if during desing time you are sure of the entities domain (What are the entities you'll be having) then keep them in separate tables so that your search can be more efficiently optimized.

However, do consider what if the attributes for an entity need to be updated (added, edited, removed etc), so if you keep them in one table the update may affect all the others. And what if later on you need to add a relation with or to your table. All the unrelated entities may also inherit the relationship.

S M Kamran
A: 

Regarding your Dataprovider class - if it gets too big, this could be considered a code smell which is generally thought of as a bad practice. Deciding how big is too big is somewhat subjective.

From the article:

Large class: a class that has grown too large, see God object.

Andy West
+2  A: 

Always put lookups in their own tables so that you can have meaningful foreign keys on related tables for relational integrity (ie CountryID in Customer table references CountryID in Country table).

Your lookup schema may diverge from the standard ID / Description on a per-entity basis as well, so 'one-size-fits-all' is not the best way to start.

Also, have one repository / data provider per lookup, don't mash them all into one big class as that will get unwieldy and untesty.

Sam
+4  A: 

Trust me, the time will come when someone says, "hey, can we add latitude/longitude to cities", and you'll be kicking yourself because those properties make no sense with car makes and models.

You can't really go wrong with physically separating unrelated, disjoint entities. So I'd recommend different tables.

Juliet
But equally they might say, "Hey, can we add a DateCreated field to all those entities"
cxfx
thanks to all, this makes more sense.
Parminder
I already have datecreated, modifydate fields, but I think they dont make much difference in case of one or more than one table.
Parminder
+1 i faced same issue after storing it in same table, in addition to add new fields for entity some time it also requires relation ship between entities i.e. City should be filtered based on state selection
Harryboy
but that can be done using some ParentID kind of field.
Parminder
cxfx, even if you have a couple hundred individual list tables, you can easily write a script to automate adding a column to each one. I could write something like that in SMO without too much trouble, for instance.
Kyralessa
+2  A: 

I've seen it done both ways, but in terms of discoverability, I much prefer having a separate table for each piece of data. It's not that difficult to maintain the multiple tables, and it makes things much easier down the road when you decide you need to add a column or two to one of the items.

Kyralessa
A: 

If you think that over time the different types of data will acquire different properties, then put them each in their own table. However, if you reckon they're all always going to stay as just Id and Description then, for simplicity, put them all in the same table with a TypeId.

I agree with the other answers that advise using a third-party data access or OR/M component, like LINQ-to-SQL, NHibernate, SubSonic, LLBLGen Pro, etc.

cxfx