Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Web Application MySQL Data Access

Posted on 2014-04-17
3
Medium Priority
?
593 Views
Last Modified: 2014-04-18
Hi,

I'm designing a c# class to retrieve data from MySQL in order to provide it to a C# Web Application which will be coded in the future by someone else.  I would like to avoid  passing parameters by reference and/or using out parameters.  My question is what would be the "best" way to structure the class methods?  Some of them will need to return just a success code with a success message.  For these, I'm using something like :

class ReturnValue
{
    int fail;  // will be zero if successful
    string failMessage;   // will be empty if successful
}
ReturnValue returnValue ProcessPayroll(parameter1, parameter2);

Other methods will need to return rows of data along with some sort of success code.  For these I'm using something like:

class GetEmployeesReturnValue
{
    ReturnValue returnValue;
    List<Employee> employees;
}
GetEmployeesReturnValue getEmployeesReturnValue getEmployees(parameter1, parameter2);

So, just about every method will have it's own class which encapsulates it's specific "return value".
Is this something a Web Application developer will be able to easily work with?  Are there better ways for an intermediate C# programmer like myself to implement these data provider methods?

Thank you very much for reading.  And, thank you in advance for whatever advice you might provide.

Curt
0
Comment
Question by:97WideGlide
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Dennis Aries earned 2000 total points
ID: 40008374
This is something a webdeveloper can easily work with.

There is no single 'best' solution since a lot of that descision is based on the design of the solution.

I would recommend using an array instead of the List-object. While the List-object is easy to use, that design is not supported in all languages whereas a simple arary is. For your code it will only mean that you use "mylist.ToArray()" to convert your List-object to a static array.

You might also consider using inheritance:
class ReturnValue {
  public bool Status; // true when success, false otherwise
  public string FailureReason;
}


class EmployeeReturnValue: ReturnValue {
// This class will automaticly inherit the properties and functions of the ReturnValue-class
  Employee[] employees;
}

Open in new window


This way, the webdeveloper can use a centralized function that accepts the ReturnValue-class to check the result and pass any of the results he receives.
0
 
LVL 8

Author Comment

by:97WideGlide
ID: 40009513
Great! Thank you very much for your answer.  It helps me alot!  And thank you for pointing out that I can inherit from ReturnValue.
0
 
LVL 8

Author Closing Comment

by:97WideGlide
ID: 40009516
Great! Thank you very much for your answer.  It helps me alot!  And thank you for pointing out that I can inherit from ReturnValue.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question