Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am designing an architecture in .NET framework. I use the Three tier model to design my application but I have a concern about how is the way to properly model the access to database layer. I have separate DLL for each layer.

In my business layer I want to access the database, for example to add new registry in a way that the members are not passed each one in a parameter but all in a single object. For example:

<br /><br />namespace myapp.bussines_layer<br />{<br />class Point<br />{<br />  int x;<br />  int y;<br /><br />  MyDatabase db = new MyDatabase();<br /><br />  //I want this...<br />  void InsertInDatabase()<br />  {<br />    db.NewRowInDB(this);<br />  }<br /><br />  //... instead of this<br />  void InsertInDatabase()<br />  {<br />    db.NewRowInDB(this.x, this.y);<br />  }<br />}<br />}<br />


The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function.

Does my idea fit correctly in the good practices and designs to access databases? Is better design to pass all the parameters as native types (even when the amount os parameter is high)??

I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers.

Thank you very much in advance.

Julen.
Posted

Julen wrote:
I use the tree tier model


It's "three-tier", as in the number 3, not "tree tier".

 
Share this answer
 
Hi,

In order to eliminate the circular dependencey and to follow the best practice, it would be better to create the class library project which resembles the business entities( in this case Point etc). and refer this both from Business Layer and the Data Layer. By doing this it helps to achieve loose coupling, re use, modularity etc.

I hope this helps!.

Regards,
-Vinayak
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900