How to Implement abstraction, parent-child relationship in an access database

374 views Asked by At

the following is the tentative class diagram for an application I am working on. I am going to use C# to query my Access database (I won't be using LINQ). My question is about Parent-child relationship between Customer class (parent/abstract class) and three other child classes that derive from it, Retailer/Business, Corporate, and Consumer. I have designed the class on diagram and that is how I intend to implement in C#, what I don't know is how do I implement this in MS Access database. Should I create a table for the parent class which is Customer, and then three other tables for the three child classes? How do I define relationships as parent-child and how do I query them? For example if I am looking for ALL Customers do I query just the customer table or all of its child tables too? Please ignore the attributes for now as I am going to refine them later. Thanks.

Low reputation wouldn't let me past image here directly, so I have put the image of class diagram here, please have a look.

http://postimg.org/image/wesl37i8f/

1

There are 1 answers

1
Krish On BEST ANSWER

I think all you need is some basic database lessons: here: http://code.tutsplus.com/tutorials/relational-databases-for-dummies--net-30244 https://www.google.co.uk/search?q=how%20to%20create%20relational%20database&gws_rd=ssl

you are almost there with your class diagram, now you have to identify identities and normalize them. Yes for all of your classes you need to create a table.

how to define relationships: in your class diagram you have [customer_table] and [business, corporate, consumers] in a rational database you would have a [customer_table] in the [customer_table] you would have a [customer_type_id] which acts as a linking key to your [customer_type] table.

if you create a new customer, you would then select a customer type from your customer_type table and this would be a simple relationship.

to query customer table: if you want to get all customers details you can only query the customer_table. if you want to know what type of customer they are you would link [customer_table] with [customer_type_table] something linke

select customer_table.customer_name, customer_type_table.customer_type
from customer_table inner join customer_type_table on customer_Table.customer_type_id = customer_type_table.customer_type_id

look at the above links they might help you to understand more. if you are stuck you can post whatever you have tried so far. good luck