Farhad-Taran
Farhad-Taran

Reputation: 6512

How can I structure my data?

I have two classes(Book,Software) that inherit from the Product class. these two classes have some fields that are different from each other. if i am to save the data for both these classes to a single table it would cause some columns to have null values.

if i save the data into different tables(Books table and Software Table) and then wanted to view this data in a single gridview, would i have to join the data and then load it to the gridview?

I would like to add 2 more classes(IndividualCustomer, WholesaleCustomer) later on which will inherit the Customer class in the same manner as mentioned above.

please guide me towards the best approach.thank you

Upvotes: 1

Views: 120

Answers (3)

Peter Kiss
Peter Kiss

Reputation: 9319

The Books and Softwares are not different Products they are just different Categories.

I would create several tables: Products Categories Properties PropertiesToCategories PropertiesToProducts

In this form you can attach some property to each category, example: Books has Author, Title, Publisher

When you want to add a new Product you should choose first it's Category and then you can attach the available (for Books: Author, Title, Publisher) properties to your new product.

Upvotes: 1

Joe
Joe

Reputation: 15802

I'm no C# programmer, but I'd go with something like

`products` table
 - product_id (pk)
 - title
 - price
 - etc

`products_software` table
 - software_id (pk)
 - product_id (foreign key, relates to a product_id)
 - serial_number
 - storage_media

`products_books` table
 - book_id (pk)
 - product_id (foreign key, relates to a product_id)
 - pages
 - author

Upvotes: 3

Andrea Colleoni
Andrea Colleoni

Reputation: 6021

In situations like this I create three tables: Product, Book and Software.

In Product I'll put the PK and all common fields; in Book the same PK and book specific fields; the same as Book for Software.

The associations between these kind of tables should be 1:1.

Upvotes: 3

Related Questions