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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:45:58+00:00 2026-05-25T09:45:58+00:00

I am not sure where/how to search for this question so I thought asking

  • 0

I am not sure where/how to search for this question so I thought asking the comminuty of stackoverflow is the best bet.

Basically I am designing a Project which will simply provide a logic project access to a LINQ to SQL model to perform CRUD on a database. So within the Data project I have the LINQ to SQL model class and a C# class to provide access to the Model as shown below

public class Connection : IDisposable
{
    private DataModelDataContext _model;
    public DataModelDataContext model
    {
        get { return _model; }
        set { throw new Exception("Object \"model\" is not allowed to be created outside of its container class", new NotSupportedException()); }
    }

    public Connection(string username, string password)
    {
        User u = _model.Users.Where(u => u.Username == username && u.password == u.Password);

        if (u == null)
            throw new ApplicationException("User credentials are invalid", new AuthenticationException());
        _model = new DataModelDataContext();
    }

    public void refreshAndKeepChanges(object entity)
    {
        _model.Refresh(RefreshMode.OverwriteCurrentValues, entity);
    }

    public int getChangesCount()
    {
        return _model.GetChangeSet().Deletes.Count() + _model.GetChangeSet().Inserts.Count() + _model.GetChangeSet().Updates.Count();
    }

    public void Dispose()
    {
        _model.SubmitChanges();
        _model.Dispose();
    }
}

What I want is, when I compile the DLL is for the Logic project to have access to the Connection class (above) but not the DataModelDataContext (as this would defeat the object of passing user credentials).

My question is how can expose the Connection class (as public which I have already done) but hide LINQ to SQL data model from the DLL but allow the Connection class access to it???

using an extra namespace for the LINQ to SQL model does not work, i have found adding the DLL allows access to all the namespaces within the project.

  • 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-25T09:45:59+00:00Added an answer on May 25, 2026 at 9:45 am

    Just change the model property to be internal, along with the DataModelDataContext class (which is probably done by editing the DBML, either in the designer or by hand). It’s fine for the Connection class to know about internal classes – it just can’t expose them publicly.

    As a couple of asides:

    • If the model setter is never going to be functional, why have it at all? Just get rid of it.
    • You should start following the .NET naming conventions
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I am not sure if this question fits best on SO,
tried to search for this, although I am not even sure what I am
I'm not even sure what this principle is called or how to search for
I need to search for initials (not sure if this is the right name,
So, if this question has been asked before, I'm sorry. I'm not exactly sure
Not sure if this is the proper place to post this question, but I've
I'm sorry if this question has been asked before, but I'm not even sure
First off I'm not sure that's the proper title for this question but hopefully
I'm not sure what to search for exactly so i'm hoping the community can
I'm not sure about clarity of the STAR word. I'm implementing a search method

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.