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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:41:18+00:00 2026-05-27T08:41:18+00:00

After reading on the benefits (and using) the Repository Design pattern within an ASP.NET

  • 0

After reading on the benefits (and using) the Repository Design pattern within an ASP.NET MVC 3.0 project, I’ve come across a certain issue which got me puzzled and started to question the benefits of the pattern. Perhaps someone could help me clarify this.

I have the following 3 TABLES:

  • –User (parent)
  • –UserLead (child of User)
  • –UserLeadNotes (child of UserLead)

Roughly, the tables and their relationships are designed like this:

  • User [Id]
  • UserLead [Id, UserId (Foreign Key)]
  • UserLeadNotes [Id, UserLeadId (Foreign Key)]

I have a BaseRepository which include the basic CRUD methods.
(IEnumerable<TEntity> Get(), TEntity GetByID(), Insert(), Delete(), etc…)

With that in place, I also have a Service Layer which calls the appropriate repositories when and if needed.

In a nutshell, the application displays a UserLead and allows a user to add/remove notes to that UserLead (which are stored/deleted in the UserLeadNotes table). Adding/removing notes are done via Ajax calls. The removing of a note passes along the “id” of the note I wish to delete.

Now…before I actually delete the note, I need to make sure that the note truly belongs to the current logged in user (User.Identity.Name aka UserId)

Considering my method deleteUserNote(int noteId) only receives a “noteId” parameter AND considering that my UserLeadNotes TABLE does not have a foreign key on UserId, what I need to do, is add an

.Include(“UserLead’)

inside my _userLeadNoteRepository to have something like:

UserLeadNote userLeadNote = _userLeadNoteRepository
                .AllIncluding(p => p.UserLead)
                .FirstOrDefault(p => p.UserLeadNoteID.Equals(noteId) 
                   && p.UserLead.UserID.Equals(User.Identity.Name));

Then I would delete the UserLeadNote object that I just found:

_userLeadNoteRepository.Delete(userLeadNote);

Questions:

Following the above approach, this would force me to a) create a Repository for my UserLeadNotes and b) because of the .Include() the userLeadNote object found would have a property called UserLead holding all the fields defined in the UserLead table.

If my UserLead table happens to have 14 fields and 10 of these fields are ntext, that means I would be loading/holding too much information for nothing!

If I was to use, instead of a Lambda expression, a Linq statement bypassing the repository and directly use my Context:

using(MyContext db = new MyContext ())
            {
                var query =
                    from uln in db.UserLeadNote
                    join ul in db.UserLead on uln.UserLeadID equals ul.UserLeadID
                    where uln.UserLeadNoteID == userLeadNoteID
                        && ul.UserID == User.Identity.Name
                    select uln;

                var userLeadNote = query.FirstOrDefault();

                db.UserLeadNote.Remove(userLeadNote);

                db.SaveChanges();
            }

Wouldn’t this approach be more efficient as it would not bring back those unnecessary fields from the UserLead table? (Those 10 ntext field for example).

Unless I’m not using the Repository Pattern correctly, or perhaps this is an Entity Framework issue, I’d like to know what anyone thinks!

Keep in mind, that I am aware of the benefits of having a Repository Pattern in place but curious if this is some kind of issue people are having or not. And if so, have they decided to drop the Pattern and directly use their Context using Linq statements.

What’s the lesser of two evils?

  • 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-05-27T08:41:19+00:00Added an answer on May 27, 2026 at 8:41 am

    In conclusion,

    After reading Ryan’s and Rouen’s posts, It appears that creating one Repository per Entity might not be the appropriate approach. If I have a child (or child of child) entities, I should be instead creating a single Parent Repository and navigate my way trough the child (or child of child).

    The problem I was confronted with is that when trying to delete a child of a child entity (that did not have the Parent’s foreign key) I had to .Include(“”) those other “upper” tables. (In my case it was only one table, the Parent but one could easily have to delete a child of a child of a child and would have to Include() many “parents/upper” tables).

    In the end, Including the Parent table created a property which held all the fields of the Parent and in my case, that was considered “getting” too much information for my simple task at hand.

    This so called problem, could be avoided if I was to drop the usage of the Repository Pattern and instead, directly use the Context.

    For some, this might not be a problem (or they simply don’t know what’s happening) and for others, having the Pattern in place outweighs the Cons it may have.

    I haven’t decided yet on completely dropping the Repository Pattern since I like what it brings to the table.

    Thanks to all.

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

Sidebar

Related Questions

After reading Steven Sanderson's book Pro ASP.NET MVC I am convinced about the benefits
After reading the Head First Design Patterns book and using a number of other
I have been reading page after page after page about the benefits of using
After reading the most excellent book Head First Design Patterns, I began proselytizing to
After reading documentation on paypals developers website for quite a while, I've come to
After reading through the documentation. Ive come to realize the selector method is what
After reading this question , I was reminded of when I was taught Java
After reading a bit more about how Gnutella and other P2P networks function, I
After reading Practical Common Lisp I finally understood what the big deal about macros
After reading this description of late static binding (LSB) I see pretty clearly what

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.