Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:21:27+00:00 2026-06-05T15:21:27+00:00

I want to create a wrapper class so that all queries should not be

  • 0

I want to create a wrapper class so that all queries should not be in controller. Currently select queries are placed in Controller. But I want to create another layer for abstraction.

I already created a viewmodel class. But wrapper class is something else.

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:21:28+00:00Added an answer on June 5, 2026 at 3:21 pm

    I don’t do any queries directly in my controllers. I have a service layer which my controller would call, and each service layer would do a call to the repository to insert, update or delete data or bring back data.

    The sample code below uses ASP.NET MVC3 and Entity Framework code first. Lets assume you want to bring back all the countries and use it for whatever reason in your controller/view:

    My database context class:

    public class DatabaseContext : DbContext
    {
         public DbSet<Country> Countries { get; set; }
    }
    

    My country repository class:

    public class CountryRepository : ICountryRepository
    {
         DatabaseContext db = new DatabaseContext();
    
         public IEnumerable<Country> GetAll()
         {
              return db.Countries;
         }
    }
    

    My service layer that calls my repository:

    public class CountryService : ICountryService
    {
         private readonly ICountryRepository countryRepository;
    
         public CountryService(ICountryRepository countryRepository)
         {
              // Check for nulls on countryRepository
    
              this.countryRepository = countryRepository;
         }
    
         public IEnumerable<Country> GetAll()
         {
              // Do whatever else needs to be done
    
              return countryRepository.GetAll();
         }
    }
    

    My controller that would call my service layer:

    public class CountryController : Controller
    {
         private readonly ICountryService countryService;
    
         public CountryController(ICountryService countryService)
         {
              // Check for nulls on countryService
    
              this.countryService = countryService;
         }
    
         public ActionResult List()
         {
              // Get all the countries
              IEnumerable<Country> countries = countryService.GetAll();
    
              // Do whatever you need to do
    
              return View();
         }
    }
    

    There are lots of info on the internet on how to get you data and display it, inserting, editing, etc. A good place to start is at http://www.asp.net/mvc. Work through their tutorials, it will do you good. All the best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create an uebersimple class that implements get enumerator, but failing madly due
I want to create wrapper class, which will enable keys duplicates while default hash
Let us say that I want to create a class MyString which is a
i want to create some simple wrapper classes for an existing class library. To
I want create module which update list of usb devices automatically (not only mass
I want to create a class with a nested enum. public class Foo {
I want to create a stored procedure (on SQL Server 2005) that fetches a
I want to create conditional comments in XSLT. But when I use this: <!--
So I have a wrapper class that when I send it a message, it
Here's what I'd like to do: I want to create a library project that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.