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

The Archive Base Latest Questions

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

I have a site where users are allowed to create as many micro-sites with

  • 0

I have a site where users are allowed to create as many micro-sites with in the main site as they like. A user can also set other users as moderators of their micro-site and users can follow other micro-site. I am not sure what I am doing wrong, (this seemed to work with CTP3), but when I try to do simple stuff like

var site = _siteRepo.SingleOrDetault(x => x.Id == id);

site.Moderators.Add(user1);

I get an System.NullReferenceException: Object reference not set to an instance of an object.

This is what my entities look like and how I mapped them.

 public class User : IEntity
    {
        private DateTime _createdAt;
        private DateTime _lastActivityAt;
        public User()
        {
            _createdAt = SystemTime.Now();
            _lastActivityAt = SystemTime.Now();
        }

        public virtual long Id { get; private set; }
        public virtual string Email { get; set; }
        public virtual string Name { get; set; }
        public virtual string PasswordHash { get; set; }
        public virtual string PasswordSalt { get; set; }
        public virtual bool IsConfirmed { get; set; }
        public virtual ICollection<Site> Moderator { get; set; }
        public virtual ICollection<Site> Following { get; set; }
        public virtual ICollection<Site> Sites { get; set; }
        public virtual DateTime LastActivityAt
        {
            [DebuggerStepThrough]
            get { return _lastActivityAt; }
            [DebuggerStepThrough]
            set { _lastActivityAt = value; }
        }
        public virtual DateTime CreatedAt
        {
            [DebuggerStepThrough]
            get { return _createdAt; }
            [DebuggerStepThrough]
            set { _createdAt = value; }
        }

        public Role Role
        {
            get { return (Role) InternalRole; }
            set { InternalRole = (int) value; }
        }
        [EditorBrowsable(EditorBrowsableState.Never)]
        public virtual int InternalRole
        {
            [EditorBrowsable(EditorBrowsableState.Never)]
            get;
            [EditorBrowsable(EditorBrowsableState.Never)]
            set;
        }
    }

public class Site : IEntity
    {
        private DateTime _createdAt;

        public Site()
        {
            _createdAt = SystemTime.Now();
        }
        public virtual long Id { get; set; }
        public virtual string Slug { get; set; }
        public virtual bool IsPrivate { get; set; }
        public virtual bool IsActive { get; set; }
        public virtual bool IsAdminRestricted { get; set; }
        public virtual bool HasDonationPage { get; set; }
        public virtual SiteData SiteData { get; set; }
        public virtual Theme Theme { get; set; }
        public virtual User User { get; set; }
        public virtual ICollection<User> Moderators { get; set; }
        public virtual ICollection<User> Following { get; set; }
        public virtual ICollection<SiteAnnouncement> SiteAnnouncements { get; set; }
        public virtual ICollection<SiteLink> SiteLinks { get; set; }
        public virtual ICollection<SitePost> SitePosts { get; set; }
        public virtual SiteDonation SiteDonation { get; set; }
        public virtual DateTime CreatedAt
        {
            get { return _createdAt; }
            set { _createdAt = value; }
        }

    }


        public UserMap()
        {
            HasKey(u => u.Id);
            Property(u => u.Id).IsIdentity();
            Property(u => u.Name).IsRequired().IsVariableLength().HasMaxLength(75);
            Property(u => u.Email).IsRequired().IsVariableLength().HasMaxLength(75);
            Property(u => u.PasswordHash).IsRequired().IsVariableLength().HasMaxLength(215);
            Property(u => u.PasswordSalt).IsRequired().IsVariableLength().HasMaxLength(88);
            Property(u => u.IsConfirmed);
            Property(u => u.LastActivityAt);
            Property(u => u.CreatedAt);
            Property(u => u.InternalRole);
            MapSingleType(u => new
                                   {
                                       u.Id,
                                       u.Name,
                                       u.Email,
                                       u.PasswordHash,
                                       u.PasswordSalt,
                                       u.IsConfirmed,
                                       Role = u.InternalRole,
                                       u.LastActivityAt,
                                       u.CreatedAt
                                   }).ToTable("User");
        }

        public SiteMap()
        {
            HasKey(s => s.Id);
            Property(s => s.Id).IsIdentity();
            Property(s => s.HasDonationPage);
            Property(s => s.IsActive);
            Property(s => s.IsAdminRestricted);
            Property(s => s.IsPrivate);
            Property(s => s.Slug).IsRequired().IsVariableLength().HasMaxLength(125);
            Property(s => s.CreatedAt);
            MapSingleType(s => new
                                   {
                                       s.Id,
                                       ThemeId = s.Theme.Id,
                                       UserID = s.User.Id,
                                       s.HasDonationPage,
                                       s.IsActive,
                                       s.IsAdminRestricted,
                                       s.IsPrivate,
                                       s.Slug,
                                       s.CreatedAt
                                   }).ToTable("Sites");
        }
  • 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-16T17:17:44+00:00Added an answer on May 16, 2026 at 5:17 pm

    Need to null check property of ICollection before adding objects to it.

    Or set a default in the constructor:

    public User()
            {
                _createdAt = SystemTime.Now();
                _lastActivityAt = SystemTime.Now();
                Moderator = new List<Site>();
                Following = new List<Site>();
                Sites = new List<Site>();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC 2 app I am building and users are allowed
I have some extra features on a site that employees can use but customers
This is regarding ASP.NET MVC. Let's say I have a web site that is
I have two roles being used on my site currently, author & admin. Authors
I'm trying, in vain, to create a simple Django template tag to either show
I have a custom routing class that checks versioning of an object to allow
When i validating my site i got following issue <embed src=banner.swf quality=high pluginspage=http://www.macromedia… ✉
So all of the pages on my web application have URIs of the form
In my robots.txt i have this: Disallow: /lo lo is a directory with a

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.