I am trying to work out the best way to separate my domain objects from my database.
The scenario I have is the following : I have a companies table, in my application I want to be able populate a prospect object but in that objects lifecycle it will cease to be a prospect and become a opportunity (which is another domain object) which should be treat in another way(hence another domain object). I am trying to find a way to show this correctly in my relational database.
I could have a prospects and a opportunity table which holds Ids of the companies, so I know which are opportunities and which are prospects, Or I could put bools on company which says if it is a prospect or opportunity. I feel like both of these aren’t correct.
Any advice would be gratefully received.
Why do you feel as if the multi table solution is wrong?
The things that happen specifically to prospects can be in that table, opportunities in that one, whereas companies can keep information solely for companies in it.
I hope you don’t mean a single boolean which indicates whether a company is a prospect or an opportunity. Because the minute you want a third state, you’re already boned. If you want to go the flag route, you have to ask yourself if these states are mutually exclusive or not. Can a company be both a prospect and an opportunity? If so, multiple flags would be preferred. If not, a single field indicating the state of the company would be better.
I mean, basically, you’re recreating a Customer Relationship Manager. I’ve typically seen them use a separate table for prospects and opportunities as there’s usually specific information related to those items stored. Not to mention you can have multiple prospects and opportunities for a single company. If you have the opportunity to sell them 50 whosits and later have the opportunity to sell them 20 whatsits, that’s two distinct opportunities.
Basically, when you come to these design questions, you have to ask yourself, “Can I see a case where this would be useful?” Or “How could this be wrong?”
Also, this question isn’t really related to C# except for the fact that you’re implementing your solution in C#.
C# devs
null reference exceptions