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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:06:51+00:00 2026-05-15T01:06:51+00:00

I need help with accessing class properties within a given class. For example, take

  • 0

I need help with accessing class properties within a given class.

For example, take the below class:

public partial class Account
    {
        private Profile _profile;
        private Email _email;
        private HostInfo _hostInfo;

        public Profile Profile
        {
            get { return _profile; }
            set { _profile = value; }
        }

        public Email Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public HostInfo HostInfo
        {
            get { return _hostInfo; }
            set { _hostInfo = value; }
        }

In the class “Account” exists a bunch of class properties such as Email or Profile.
Now, when I want to access those properties at run-time, I do something like this
(for Email):

    _accountRepository = ObjectFactory.GetInstance<IAccountRepository>();
    string username = Cryptography.Decrypt(_webContext.UserNameToVerify, "verify");
    Account account = _accountRepository.GetAccountByUserName(username);

    if(account != null)
    {
        account.Email.IsConfirmed = true;

But, I get “Object reference not set…” for account.Email… Why is that?
How do I access Account such that account.Email, account.Profile, and so on
returns the correct data for a given AccountId or UserName.

    Here is a method that returns Account:

public Account GetAccountByUserName(string userName)
{
    Account account = null;

    using (MyDataContext dc = _conn.GetContext())
    {
        try
        {
            account = (from a in dc.Accounts
                       where a.UserName == userName
                       select a).FirstOrDefault();
        }
        catch
        {
            //oops
        }
    }

    return account;

}

The above works but when I try:

 account = (from a in dc.Accounts
               join em in dc.Emails on a.AccountId equals em.AccountId
               join p in dc.Profiles on em.AccountId equals p.AccountId
               where a.UserName == userName
               select a).FirstOrDefault();

I am still getting object reference exceptions for my Email and Profile
properties. Is this simply a SQL problem or is there something else I need to be
doing to be able to fully access all the properties within my Account class?

Thanks!

  • 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-15T01:06:52+00:00Added an answer on May 15, 2026 at 1:06 am

    Are you declaring these properties yourself, or are you trying to indicate something like auto-generated code from like Linq-to-SQL?

    If this is auto-generated where the Account table references the Email table, etc., then you probably just need to specify that you want those objects to load as well in the load options:

    using (MyDataContext dc = _conn.GetContext())
    {
        var options = new DataLoadOptions();
        options.LoadWith<Account>(a => a.Email);
        options.LoadWith<Account>(a => a.Profile);
        options.LoadWith<Account>(a => a.HostInfo);
    
        dc.LoadOptions = options;
    
        try
        {
            account = (from a in dc.Accounts
                       where a.UserName == userName
                       select a).FirstOrDefault();
        }
        catch
        {
            //oops
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with accessing class from Form. So I'll put my code so
need help in error in database pivot. i have table tamed table_score like below:
My brain is not working this morning. I need some help accessing some members
I am new to Ruby and need help in accessing a function which is
I need help with users accessing my site via HTTPS. I only want to
I need a way of accessing directly an instance of a class through an
I posted a detailed question here: https://stackoverflow.com/questions/4252194/need-help-closing-accessing-my-views-in-a-simple-app-included-an-img-of-my-progr but I might have been too confusing.
Public Class frmMain Private p_dlgAdd As frmAdd = Nothing Public ReadOnly Property _dlgAdd As
I'm trying to do a very basic setup of LinkedIn - accessing public profile
I need some help accessing a value in my arrayCollection in Flex 3. var

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.