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

x
?
Solved

Using ADO.NET instead of Entity Framework

Posted on 2014-04-19
6
Medium Priority
?
713 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

886 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