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

The Archive Base Latest Questions

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

I want to set up the access strategy so that if a field.camelcase-underscore property

  • 0

I want to set up the access strategy so that if a field.camelcase-underscore property backing is present then use that else use the automatic property.

is this the default behavior (since auto props have back fields essentially)? or how to I enforce this?

  • 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-13T17:43:51+00:00Added an answer on May 13, 2026 at 5:43 pm

    The default is to use the setter of the property, so you need to specify access as camelcase underscore field (or whatever naming convention you use) if you have a backing field.

    There might be a simpler way to achieve this, but you can use Fluent NHibernate’s conventions to enforce this behaviour of using backing fields if available, and setters otherwise. When the convention is applied you can reflect over the entity type to check if there is a corresponding camelcase underscore field or not. If a backing field is found, you modify the mapping to use camelcase underscore as access.

    Here is an example using IPropertyConvention. (You might want to do the same kind of check in a one-to-many convention etc as well):

    public class PropertyAccessConvention : IPropertyConvention
    {
        public void Apply(IPropertyInstance instance)
        {
            Type entityType = instance.EntityType;
            string camelCaseUnderscoreName = 
                ConvertToCamelCaseUnderscore(instance.Name);
    
            bool hasBackingField = HasField(entityType, camelCaseUnderscoreName);
    
            // Default is to use property setter, so only modify mapping
            // if there is a backing field
    
            if (hasBackingField)
                instance.Access.CamelCaseField(CamelCasePrefix.Underscore);
        }
    
        private static string ConvertToCamelCaseUnderscore(string propertyName)
        {
            return "_" +
                propertyName[0].ToString().ToLower() +
                propertyName.Substring(1);
        }
    
        private bool HasField(Type type, string fieldName)
        {
            FieldInfo backingField = type.GetField(
                fieldName, 
                BindingFlags.NonPublic | BindingFlags.Instance);
    
            return backingField != null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set up a Django server that allows certain users to access
I want to set a variable in index.php and want to access that variable
If I want to set a variable that my whole controller can access, how
I want to set a binding. The problem is that the target is of
I want to set the maxChars property of the TextInput of an editable ComboBox.
I want to set up a single virtual host that can dynamically handle all
I Want Set Access level user For Buttons in the forms. example in the
I am using the latest version of GlassFish. I want to set the Access-Control-Allow-Origin
I just want to prerender different images for fast access. I use grand central
I want to set an env variable that has the DOC_ROOT info but nothing

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.