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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:33:36+00:00 2026-05-17T17:33:36+00:00

I am sortof using a repository pattern to extract information from a database. I

  • 0

I am sortof using a repository pattern to extract information from a database. I have two classes, report and reportRepository.

The trouble I have is that since reportReposity has to fill in all the details for the report object, all the members in the report have to be publicly accessible.

Is there a way so that I can ensure that only the repository class can access some of the methods of the report class and only it can set some of the properties that other classes cannot, sort of like what friend does in c++. Or is there a completely different way of handling this situation?

I am using C# in ASP.NET 2.0

  • 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-17T17:33:37+00:00Added an answer on May 17, 2026 at 5:33 pm

    This looks a bit funky but it does what your after, any property with a ‘protected’ modifier will only be accessable within that class AND any derived classes

    public class Person
    {
        public string Name { get; protected set; }
        public int Age { get; protected set; }
    }
    
    public class PersonRepository
    {
        public Person Get()
        {
            return new PersonBuilder("TestName", 25);
        }
    
        private class PersonBuilder : Person
        {
            public PersonBuilder(string name, int age)
            {
                this.Name = name;
                this.Age = age;
            }
        }
    }
    

    So unless your within the repository you can’t see the Person derived class PersonBuilder which has a constructor that populates the protected properties of Person. Externally it looks like your magically populating fields without using setters or constructors.

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

Sidebar

Related Questions

I'm trying to delete a database record using ASP.NET MVC, Fluent, and NHibernate. See
I have a UISlider that is supposed to update the color of a textlabel.
I have never used ClearCase, but have used Subversion and for a short period
After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf
I'm thinking of using pure/const functions more heavily in my C++ code. ( pure/const
I understand one of the (maybe best) ways of using inversion of control is
I am new to both MVC as well as Entity Framework, but I want
I've pretty much finished work on a white noise feature for one of my
I've been playing about with the layout of a view with Android (lets say
I'm thinking of implementing a configuration file written in Python syntax, not unlike 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.