c# - What is the most DRY way to get data out of my database? -


I have to write an ASP.NET application that connects to our legacy IBM Universe database and we are using a product Which is called MV Net, which allows us to connect, read, write, select, run server side programs and so on.

I want to repeat the code as small as possible, but I also want a little data transfer as possible as possible.

To open a connection, we will first need to get a context reference using the code like:

  mvAccount myAccount = new mvAccount (serverName, login) ;  

Then we can read an item:

  mvFile myInvoiceFile = myAccount.FileOpen ("INVOICE"); MvItem myInvoiceRecord = myInvoice file. Read (invoiceID);  

Then we have done it:

  myAccount.Logout ();  

I have a class for each module, so I can have invoice, purchase, ADR, RMA, REC, shipment, and so on. Within INVOICE, I may need to access several tables like customer, INVOICE, TERMS, SHIPVIA, etc.

The plan I made was made a class called Tekdi, which is the name of our database and there is a code in my INVOICE class that I can just say:

 < Code> TechDB connection = newTDB (); MvItem myInvoiceRecord = connection.Read ("INVOICE", invoiceID)  

When I do this, my TDB class opens the connection, reads the record, and then logs all in one step Out.

I think I am going on the right path, but please tell me whether or not I do. My problems with this are:

  1. How do I return the errors of my INVOICE class? For example, if we are unable to connect to the database, an error may occur, unable to open the file, unable to read the record.

  2. What if I need to take some data from my INVOICE and then read the TERMS table; I hate to open a new connection from the database when I opened one.

  3. Do I call displacement methods on all those sections who have this? For example, mvAccount is a method to remove. Anyone in the document asks to call it, but after logout ()?

  4. Can I make a displacement method on TechDB class which is my account. Logout ()? In this way the connection will be open and when I was completely done with it I could shut it off from my INVOICE class?

Tell me the best way to handle it? My goal is a strong application that is easy to modify and as low as possible to code repitition

Use the closure, I think if you are a representative for C # then something like this: / P>

 MyAccount.loginAndDo (server name, login, representative (account) {invoice = account.read ("INVOICE"); ...}}; 

In Login & Do, you Login, call the representative, and then close the account.


Comments