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 8951081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:34:48+00:00 2026-06-15T13:34:48+00:00

I’m creating a web shop using MVC4 razor syntax, repository and Unit of work.

  • 0

I’m creating a web shop using MVC4 razor syntax, repository and Unit of work. At least that is what I’m trying to do.

I still have some doubts about the usage of repository and Unit of work and I’m hoping I can get some clarity here.

I’ve found two good tutorials regarding it.

The first one:
http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle

The second one:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

Now, I’ve read both and I’m a bit confused.
In the first one, the GenericRepository class is abstract and has TC and T. TC being a DbContext object and T being a class. In the second tut, only a class is needed.

Why these different approaches?
Is it because the second tutorial also uses Unit Of Work? Is one better than the other or is Unit Of Work not really necessarily?

In my project I have 20 tables, does this mean I have to create 20 repositories if some of those are used to create a multi-language site?

Finally, Do these repositories belong in the Model folder or in a seperate one like “Data Access Layer”?
If it’s the later, Does anything ever belong on the Model folder using repositories?

Could someone please provide clarity?

P.S.: My own repository code looks like this and works (no Unit Of Work):

IGenericRepository

namespace ArtWebShop.Data_Access_Layer
{
    public interface IGenericRepository<T> where T : class
    {
        IQueryable<T> GetAll();
        IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
        void Add(T entity);
        void Delete(T entity);
        void Edit(T entity);
        void Save();
    }
}

GenericRepository

public abstract class GenericRepository<TC, T> : IGenericRepository<T>
    where T : class
    where TC : DbContext, new()
{

    private TC _entities = new TC();
    public TC Context
    {

        get { return _entities; }
        set { _entities = value; }
    }

    public virtual IQueryable<T> GetAll()
    {

        IQueryable<T> query = _entities.Set<T>();
        return query;
    }
...

IMenuRepository

public interface IMenuRepository : IGenericRepository<menu_items_local>
{
    List<menu_items_local> GetMenuItemsByLanguage(string language);
}

MenuRepository

public class MenuRepository : GenericRepository<ArtWebshopEntities, menu_items_local>, IMenuRepository
{
    public List<menu_items_local> GetMenuItemsByLanguage(string language)
    {
        var menuItemsLocal = Context.menu_items_local.Where(m => m.cultures.name == language);
        if (!menuItemsLocal.Any()) throw new HttpException(404, "menu items not found");

        return menuItemsLocal.ToList();
    }
}

CommonController

public class CommonController : Controller
{
    private readonly IMenuRepository _menuRepository;

    public CommonController()
    {
        this._menuRepository = new MenuRepository();
    }

    public CommonController(IMenuRepository menuRepository)
    {
        _menuRepository = menuRepository;
    }

    [HandleError]
    [ChildActionOnly]
    public ActionResult MenuItems(string language)
    {
        return PartialView("_menuPartial", _menuRepository.GetMenuItemsByLanguage(language));
    }
}
  • 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-15T13:34:50+00:00Added an answer on June 15, 2026 at 1:34 pm

    After analyzing the two approaches I came to the conclusion that the major difference is that in case of the second tutorial where Unit Of Work is being used, the entity context is only declared once whereas in the first tutorial the context entity is mentioned in every repository.

    Since the first tutorial doesn’t use Unit Of Work the different repositories aren’t stored in one place.

    In conclusion I can state that the second tutorial is the better approach.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I've got a string that has curly quotes in it. I'd like to replace

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.