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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:46:36+00:00 2026-06-11T09:46:36+00:00

I’m using EF4.3. It’s my first project so I’m learning as I go along.

  • 0

I’m using EF4.3. It’s my first project so I’m learning as I go along.

There are instances where I need to implment additional constructors for entities. I create an additional partial class to do this, so entity Users, will have an associated class User2.

I’ve noticed that EF on the whole doesn’t create constructors, but there are instances like this:

public partial class User
{
    public User()
    {
        this.BookmarkedDeals = new HashSet<BookmarkedDeal>();
        this.BookmarkedStores = new HashSet<BookmarkedStore>();
    }

    public System.Guid UserId { get; set; }
    public int UserStatusId { get; set; }
    public int UserRoleId { get; set; }
    public System.DateTime CreatedOn { get; set; }
    public System.DateTime LastVisitedOn { get; set; }

    public virtual ICollection<BookmarkedDeal> BookmarkedDeals { get; set; }
    public virtual ICollection<BookmarkedStore> BookmarkedStores { get; set; }
    public virtual Subscriber Subscriber { get; set; }
}

This got me worrying a little because its so easy to add a navigation property via the designer, and code within the base constructor missed.

    public User()
    {
        this.BookmarkedDeals = new HashSet<BookmarkedDeal>();
        this.BookmarkedStores = new HashSet<BookmarkedStore>();
    }

My question is, do I need to call the base constructor from my additional contructors and should I put the code (: this User()) to call my base constructor in all cases as a safeguard?

  • 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-06-11T09:46:37+00:00Added an answer on June 11, 2026 at 9:46 am

    EF (Database First or Model First) creates those default constructors…

    public User()
    {
        this.BookmarkedDeals = new HashSet<BookmarkedDeal>();
        this.BookmarkedStores = new HashSet<BookmarkedStore>();
    }
    

    …only as a helper to instantiate the navigation collections to guard you a little bit against NullReferenceExceptions. But it is not required. If you load a User entity from the DB including the BookmarkedDeals and BookmarkedStores EF will instantiate the collections anyway. If you create a User yourself you just had to instantiate the sets manually if the constructur wouldn’t be there:

    var user = new User { BookmarkedDeals = new HashSet<BookmarkedDeal>() };
    user.BookmarkedDeals.Add(new BookmarkedDeal());
    

    If you add a new constructor I would call the default constructor to have the instantiation of the collections consistent between all constructors. But I think it must be this, not base because both constructors are in the same class, not in an inheritance hierarchy:

    public User(SomeType SomeParameter) : this()
    {
        //Do somthing with SomeParameter...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.