Solved

Using ADO.NET instead of Entity Framework

Posted on 2014-04-19
6
685 Views
Last Modified: 2014-04-21
Hello,

I'm new to MVC 4 and currently have got the idea how it works and about to start a new project however, I do not see any need of using EF or Entity Framework so instead want to use ADO.NET

Can somebody give me the idea how that can be done? do I need to create a class and then  use it anytime I need?

Is there any a step by step example on how to use ADO.NET rather EF?

Thanks,
ak
0
Comment
Question by:akohan
  • 3
  • 2
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40010183
You need to make use of the object in one of the System.Data.* namespaces (dependant on what database provider you are using). Mainly you'll need the Connection, DataReader and Command objects (also possibly the DataAdapter and DataTable objects, but probably less so for a web app).

You can get an intro to using the SqlConnection and SqlDataReader objects to query a database here

How you structure your code is entirely up to you. But some sort of data access class that you can reuse would be a good start.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 40012762
You don't have to use EF. You can use ADO.NET just the same way as you would do in say a WebForms project or any other project.

What I would do is create two separate projects, eg :
- MyProjectName.Models
   e.g. Class -> CustomerModel - This is just a plain class with customer properties

- MyProjectName.Services: This will have all the work required to fetch and store the Data i.e. executing the storedprocs. Get methods return the Model object with data and Save methods will take the appropriate model object.
 e.g.:
ICustomerService - declares two methods
              public List<CustomerModel> GetCustomers()
              public int SaveCustomer(CustomerModel customer)

 CustomerService
(Implements ICustomerService) - You do all the saving and getting work in this method

Now in your Controller you can use the CustomerService object like:

ICustomerService  service  = new CustomerService();
public ActionResult Home()
{
    List<CustomerModel> customers = service.GetCustomers();
     //Now use this customers to populate the view
}

Obviously you can use Dependency Injection and other sort of things so you don't instantiate the CustomerService in the controller manually or using separate ViewModel, etc. but the above should help you get going for now.
0
 

Author Comment

by:akohan
ID: 40012974
Hello guru_sami,

Thank you for the direction.  One last question, do you know any article or blog that can walk me through steps? I would love to start with a sample app to see how things gets hooked up logically.  

I did google for few keywords and found:

http://www.codeproject.com/Articles/361579/A-Beginners-Tutorial-for-Understanding-ADO-NET

http://www.codeproject.com/Articles/8477/Using-ADO-NET-for-beginners

Thanks,
ak
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 41

Expert Comment

by:guru_sami
ID: 40013112
This is kind of old blog series with asp.net 2.0 WebForms but other than the Presentation all the other stuff is still relevant.

http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1
0
 

Author Comment

by:akohan
ID: 40013273
Thank you so much!
0
 

Author Closing Comment

by:akohan
ID: 40013288
Great help! thanks for sharing the URL.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 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