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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:09:11+00:00 2026-06-07T13:09:11+00:00

To define an Entity Framework -serializable classes (EF Code First) we need to use

  • 0

To define an Entity Framework -serializable classes (EF Code First) we need to use public virtual properties as data holders, that later on will be used as a columns in the DB. This rids a developer off an ability to initialize an instance of an entity from a constructor. I want my entities to not only be a data “buckets”, but to also have behavior, such as constructor instantiation for new objects, and methods for data manipulation within the object.

Methods I can have I suppose, but what should I do to overcome the constructor limitation? Should I introduce the wrapper class that will instantiate an entity property-by-property and use it instead?

  • 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-07T13:09:14+00:00Added an answer on June 7, 2026 at 1:09 pm

    You can have methods “as you want”, as well as properties without setters that won’t be mapped in the db. Or properties with a NotMappedAttribute, which… won’t be mapped.

    Note : only the navigation properties (references and collections) need to be virtual for lazy loading. Not the primitive. I think this is an NHnibernate requirement.

    For the constructor(s), you can add as many parametrized constructors as you want, you just need to have ALSO a parameterless one.

    By the way, you can use object initializers as well.

    var test = new Test {
                    Name = bla,
                    Code = 2
                    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes in an Entity Framework 4.3 Code-First Model for MVC3:
I define my model in Entity Framework (code first), but how can I define
I'd like to define a relationship in an Entity Framework data model that is
I wish to use Entity Framework Code-first for a new project. So i decided
I have a Entity Framework design with a few tables that define a graph.
Using Entity Framework 4.1 code first and POCO entities in MVC3; I would like
I am making an application using MVC 3.0 Razor and Code First Entity Framework.
What are the pros & cons of using Entity Framework 4.1 Code-first over Model/Database-first
I want to use Entity Framework without app.config file. I want to define a
How to declare a one to one relationship using Entity Framework 4 Code First

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.