Solved

Using ADO.NET instead of Entity Framework

Posted on 2014-04-19
6
696 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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