Sunday, May 31, 2009 7:37 PMHello,
I'm in process of learning design patterns and object oriented programming. I have good knowledge in MS SQL and some experience with modular programming.
For my learning purposes I designed an IS for a small company. First step was on the paper where I defined all entites and their parameters. Then I created tables in SQL Server with all required data (primary key, foreign keys,...). Now I'd like to advance with my project in C# and therefore need help with some basics concepts, like:
- should I write for every table in SQL it's own class in C# (also for connections tables - many-to-many)?
- should every class have it's own Data access layer or is it enough to have only one class for Data access layer?
- if you have column ID in table1 and this column is identity(1,1) primary key, than you probably don't need setter method in class for this table?
Wednesday, June 03, 2009 9:10 AM
1. Should every table in SQL have its own class in C#?
Probably not - how you divide the data for relational technology is not the same for object technology. When designing a database the motivations are data integrity (no duplicates), speed of access and reporting on the data at a later date to name only a few. When designing classes you are more concerned with creating an accurate and useful model for developers.
For example, I would probably have customers address and personal data in seperate database tables but may model this as one Customer class.
2. Should every class have its own data access layer?
This depends on the size of your application and how you see it evolving in the future. I would split the data access for all but the smallest projects.
3. If you have column id in table1 and this column is identity(1,1) primary key...you probably don't need setter method in the class?
Correct, if the primary key is auto generated it would seem redundant to have a setter.
Hope this helps and good luck
Pl mark as answer or helpful if you found this useful
Wednesday, June 03, 2009 11:24 AMThanks G Moore!
Monday, June 25, 2012 3:55 AM
Why don't you use ORM frameworks such as Entity Framework, they handle all those frustrating stuffs.
Brainstorm your Brain and find solution,if no result stuck to Brainstormer.