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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:31:00+00:00 2026-05-22T12:31:00+00:00

I am using poco objects I wrote with entity framework. I would like to

  • 0

I am using poco objects I wrote with entity framework.
I would like to know about the accessibility levels of the members that used as data fields (members that mapped to field in table from the database:
For entity named P:

public class P {
    public virtual long Id{get;set;}
    public virtual string Name{get;set;}
    public virtual long CompanyId{get;set;}
    public virtual Company Company{get;set;}
}

Does the members must be public?
Does the members must be virtual?
Does the members can be private?

What are the rules for the members accessibility?

  • 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-22T12:31:00+00:00Added an answer on May 22, 2026 at 12:31 pm

    This strongly depends on the approach you are using.

    Model / Database first:

    • Members don’t have to be public but it has some consequences. POCO property getters and setters must have same accessibility as defined in EDMX (shown in linked answer). Changing accessibility will most probably break either tracking proxies, lazy loading or both as described in link provided by @dlev.
    • Members don’t have to be virtual. If you want lazy loading you must mark all mapped navigation properties virtual. If you want tracking proxies you must mark all other properties virtual.

    Code first (only EFv4.1):

    • In this case situation is worse. Members must be public. In special case when entity is in the same assembly as context or mapping configuration members can be internal (I skip InternalsVisibleTo because it is not very nice scenario). In case when mapping configuration is nested class of entity, members can be also private or protected but this strongly breaks whole meaning of POCO because POCO entity must contain EF dependent nested class. The whole point is that mapping is done in code and it is affected by accessibility rules.
    • virtual keyword has same meaning as in Model and Database first approaches.

    virtual keyword is needed because EF will create new type at runtime derived from entity type. This type is referred as proxy and it overrides behaviour in property getter and setter. In case of lazy loading it adds call to Load operation which triggers loading of relation when accessed first time. In case of change tracking proxies it informs ObjectStateManager / DbChangeTracker about each change to attached entity. If tracking proxies are not used EF must use snapshot tracking which evaluates all changes to attached entity during saving which is considered as much slower operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using LINQ to query my POCO objects for some time, but
I have a database table and a corresponding entity class (POCO with change tracking
We have 3 tables in our db that each have an entity in our
I started messing with EF 4.0 because I am curious about the POCO possibilities...
In my POCO class I have 16 attributes that are mapped to the database
I am wondering how you would approach this problem I have two Taxrates that
I'm trying to write a Compare method to compare properties in some POCOs using
So standard Agile philosophy would recommend making your domain classes simple POCOs which are
I have several medium-sized data sets in-memory that I need to be able to
Ok this one is might not have a straight forward answer but lets see.

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.