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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:37:26+00:00 2026-06-06T17:37:26+00:00

I have recently started teaching myself C# and Asp.net. I am trying to build

  • 0

I have recently started teaching myself C# and Asp.net. I am trying to build a simple blog application. I am confused about repository pattern usage. I have seen few tutorials and the implementation varies.

For my blog application, I have two database tables (models) – blogs and comments. Currently, I have a IDbContext which looks like this:

    public interface IDBContext
    {
        IQueryable<Blog> FindAllBlogs();
        IQueryable<Blog> FindBlogsInMonth(int month);
        Blog GetBlog(int id);
        void Add(Blog blog);
        void Update(Blog blog);
        void Delete(Blog blog);

        void Add(Comment comment);
        //void Remove(Comment comment);
    }

and I have repository which looks like this:

    public class BlogRepository : IDBContext
    {
        private BlogDb db = new BlogDb();

        public IQueryable<Blog> FindAllBlogs()
        {
            return db.Blogs.OrderByDescending(b => b.PublishDate);
        }

        public Blog GetBlog(int id)
        {
            return db.Blogs.Single(b => b.BlogID == id);
        }
...
}

The other implementation of repository pattern is something like this:

public interface IDbContext
{
    IQueryable<Blog> Blogs { get; }
    IQueryable<Comments> Comments { get; }
    int SaveChanges();
    T Attach<T>(T entity) where T : class;
    T Add<T>(T entity) where T : class;
    T Delete<T>(T entity) where T : class;
}

which calls a repository and there is separate class for queries.

What is the best method to do it?

  • 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-06T17:37:28+00:00Added an answer on June 6, 2026 at 5:37 pm

    The easiest method is to use Entity Framework directly, particularly the new DbContext functionality that showed up in Entity Framework 4.1 and later.

    The context will contain DbSet properties – each is an implementation of the repository pattern that accomplishes all of the goals you described above. IDbSet can be used if unit testing support is required.

    I’ve seen a lot of demos for the ASP.NET MVC repository patterns online that end up wrapping Entity Framework with a custom repository. It’s a waste of time – it’s code that wraps other code and doesn’t serve any direct purpose aside from adding needless complexity.

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

Sidebar

Related Questions

I have recently started playing with databases, trying to teach myself using examples. I
I have recently started a personal project that uses ASP.NET MVC (RC1 at the
I have recently started to use Twitter Bootstrap and trying to understand how it
I have recently started using RSpec for Integration testing in my Rails application, to
I have recently started on MongodDb and I'm trying to explore on replica sets
I have recently started applying for .Net jobs. I currently work in a sales
I have recently started using the Rackspace Cloudfiles CDN (Limelight), about which I have
I have recently started learning about Software as a Service and Cloud computing. Often
I have recently started following the examples from The Little Schemer and when trying
We have recently started using ImageResizer.Net over GDI+ for dynamically resizing images on our

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.