The title might be a little misleading because I didn’t really know what to call it. Here is my dbml and I am using the repository pattern to communicate between my application layer and my SQL layer. As you can see, I have four tables. Three of them have a foreign key to ContactId. I used this method because I need to store an “array”, so I made several tables. So now I am wondering how to make it so that I can “add” an email address, phone number, or address to a contact and manipulate it through the contact.
Share
The “obvious” answer is to have a Contact class which has addEmail, addPhone, and addAddress methods, plus the matching stored procedures in the database. Is there more to your question than this?
Also, while this is not directly part of your question, you may want to think about normalizing your design. The typical way to handle these types of things is with one-to-many tables. For example, your email address table would look like this:
OR maybe:
with the PK being ContactId and EmailNumber
Either way, each row stores a single email address. This should make it easier to add or remove individual emails, and removes the limit of three emails in your current design. It also makes it easier to add additional info about each email address. For example, is it a home or work address. Or, is the email address valid.