Solved

Using ADO.NET instead of Entity Framework

Posted on 2014-04-19
6
679 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now