views:

47

answers:

0

Greetings,

I'm looking for some more experienced insights into my current problem; a short description:

The setup and a simplified model.

The goal of the web application is to provide a platform for posting, searching and reacting on ads. The ads themselves fall into roughly 3 large categories:

  1. Real estate
  2. Cars
  3. Various (basically all other)

Each ad has some basic fields: a title, a description and a reference. When talking about specific ads, there are a lot more fields.

  1. For real estate there are additional prices, number of specific rooms, facilities, certificates and such. The price can be either rent or buying price.
  2. Cars have color(s), horsepower, production year, etc.
  3. Various basically have a description and a price.

In reality, each type of ad has about 30 non-recurring fields. I only presented basic fields to give you an idea.

Each category has some sub-types, for example Real Estate can be either a house, garage or apartment. Each has its own non-recurring fields.

The problems.

I'm looking for a way to properly store this in a database and code an application around it, in proper OO, 3 tier style.

First, when I think of the UI: (example) I do not want to create a control or page for each type of Ad i want to display. Let alone searching, inputting... How would I go about handling this? A base class would cause a lot of recurring case-like structures to find out to which class to cast - wouldn't it? Not to mention excessive controls that are not being used when only handling one particular Ad.

The second problem is storing this in a DB - SQL Server 2008 R2. The current version basically has one table (about 250 columns) with all possible values for every kind of ad. Its horrible - when adding a Car ad for example, about 50 fields are filled while 200 remain NULL. Surely there must be a better way? The model however is quite extensive so I'm really in the dark as to how I go about this. When looking at my BL tier, I have something like this (simplified a lot):

public class Ad
{
    public long Id { get; set; }
    public string Title { get; set; }
    public string Reference { get; set; }
}

public class RealEstateAd : Ad
{
    public string BuildingCondition { get; set; }
    public decimal ParcelSize { get; set; }
}

public class CarAd : Ad
{
    public string Color { get; set; }
    public double HorsePower { get; set; }
}

public class VariousAd : Ad
{
    public string Category { get; set; }
    public string Description { get; set; }
}

This is not entirely correct as each RealEstateAd basically has derived classes such as HouseAd, ApartmentAd, GarageAd... Am I going to far into modeling this? Should I just compromise and slam all the fields into 1 table? I realize over-modeling could have a negative impact on performance (lots of joins), but I can't help feeling a really good, proper model will help me out a lot when programming.

Comments and thoughts are greatly appreciated.