Solved

Using ADO.NET instead of Entity Framework

Posted on 2014-04-19
6
702 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
Industry Leaders: 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!

 
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

Technology Partners: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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