I have to store in database objects with different kind of properties. Also I want to group those objects in categories and the object can be part in multiple categories.
Example objects:
Book (ID, Title, Author, Description)
Movie (ID, Title, Author, Genre)
Song (ID, Title, Singer, Year)
So far I have tried two methods:
Method 1
Create a Category table with fields ( ID, CategoryName).
Create a general table and try to match table fields with object properties. Join the category with objects in a helper table
_CategoyObject_ (_CategoryID_, _ObjectID_).
This seems to be a bad practice because we have many columns with null values in general table. Also referring to the first point in this article it is a bad practice to store different objects in the same table.
Method 2
Create a Category table with fields ( ID, CategoryName).
Create table for each of the object.
Create a helper table to link the categories table with the name of the object table:
_CategoyObject_ (_CategoryID_, *Object_Table_Name*)
This method can help us find the name of the table to create the join if we want to take objects for a given category.
But this complicates the query because we should have one query to get the tables for a certain category and another query to get records of objects
This is even harder because I am currently using Entity Framework code first to create the database.
Is it better to get the data with ADO.NET instead of Entity Framework for easier data retrieval?
Can you suggest me any other method that is simpler for the questions:
Get all the objects who belongs to X category?
Get in which category Y object belongs?