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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:46:26+00:00 2026-05-24T12:46:26+00:00

We are using fluentnhibernate with automapping and we have a naming convention that all

  • 0

We are using fluentnhibernate with automapping and we have a naming convention that all columns that are foreign keys, there column name will end with “Key”. So we have a convention that looks like this:

public class ForeignKeyColumnNameConvention : IReferenceConvention
{
    public void Apply ( IManyToOneInstance instance )
    {
        // name the key field
        string propertyName = instance.Property.Name;

        instance.Column ( propertyName + "Key" );
    }
}

This works great until we created a component in which one of its values is a foreign key. By renaming the column here it overrides the default name given to the component column which includes the ComponentPrefix which is defined in the AutomappingConfiguration. Is there a way for me to get the ComponentPrefix in this convention? or is there some other way for me to get the column name for components with a property that is a foreign key to end in the word “Key”?

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

    I Have figured out a way to do this using reflection to get to the underlying mapping of the IManyToOneInspector exposed by the IComponentInstance but was hoping there was a better way to do this?

    Here is some example code of how I achieved this:

    #region IConvention<IComponentInspector, IComponentInstance> Members 
        public void Apply(IComponentInstance instance) 
        { 
            foreach (var manyToOneInspector in instance.References) 
            { 
                var referenceName = string.Format("{0}_{1}_{2}{3}", instance.EntityType.Name, manyToOneInspector.Property.PropertyType.Name, _autoMappingConfiguration.GetComponentColumnPrefix(instance.Property), manyToOneInspector.Property.Name); 
                if(manyToOneInspector.Property.PropertyType.IsSubclassOf(typeof(LookupBase))) 
                { 
                    referenceName += "Lkp"; 
                } 
                manyToOneInspector.Index ( string.Format ( "{0}_FK_IDX", referenceName ) ); 
            } 
        } 
    #endregion 
    public static class ManyToOneInspectorExtensions 
    { 
        public static ManyToOneMapping GetMapping(this IManyToOneInspector manyToOneInspector) 
        { 
            var fieldInfo = manyToOneInspector.GetType ().GetField( "mapping", BindingFlags.NonPublic | BindingFlags.Instance ); 
            if (fieldInfo != null) 
            { 
                var manyToOneMapping = fieldInfo.GetValue( manyToOneInspector ) as ManyToOneMapping; 
                return manyToOneMapping; 
            } 
            return null; 
        } 
        public static void Index(this IManyToOneInspector manyToOneInspector, string indexName) 
        { 
            var mapping = manyToOneInspector.GetMapping (); 
            mapping.Index ( indexName ); 
        } 
        public static void Column(this IManyToOneInspector manyToOneInspector, string columnName) 
        { 
            var mapping = manyToOneInspector.GetMapping (); 
            mapping.Column ( columnName ); 
        } 
        public static void ForeignKey(this IManyToOneInspector manyToOneInspector, string foreignKeyName) 
        { 
            var mapping = manyToOneInspector.GetMapping(); 
            mapping.ForeignKey ( foreignKeyName ); 
        } 
    } 
    public static class ManyToOneMappingExtensions 
    { 
        public static void Index (this ManyToOneMapping manyToOneMapping, string indexName) 
        { 
            if (manyToOneMapping.Columns.First().IsSpecified("Index")) 
                return; 
            foreach (var column in manyToOneMapping.Columns) 
            { 
                column.Index = indexName; 
            } 
        } 
        public static void Column(this ManyToOneMapping manyToOneMapping, string columnName) 
        { 
            if (manyToOneMapping.Columns.UserDefined.Count() > 0) 
                return; 
            var originalColumn = manyToOneMapping.Columns.FirstOrDefault(); 
            var column = originalColumn == null ? new ColumnMapping() : originalColumn.Clone(); 
            column.Name = columnName; 
            manyToOneMapping.ClearColumns(); 
            manyToOneMapping.AddColumn(column); 
        } 
        public static void ForeignKey(this ManyToOneMapping manyToOneMapping, string foreignKeyName) 
        { 
            if (!manyToOneMapping.IsSpecified("ForeignKey")) 
                manyToOneMapping.ForeignKey = foreignKeyName; 
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I'm using the automapping feature of FluentNHibernate and need a property that derives its
I have a Sharp Architecture based app using Fluent NHibernate with Automapping. I have
I want to create a convention for column names using Fluent NHibernate auto mapping.
I'm using FluentNHibernate and have done a many-to-many mapping but when I try to
I'm using fluentnhibernate on SQL Server 2008. I have to objects Staff public class
Using Sharp Architecture 1.9 I have a base class that inherits from the Sharp
I have a Fluent NHibernate mapping override that I am using to create a
The title pretty much explains it all, I have a Member object that references
i'm using oracle with FluentNHibernate automapping with alterations & NHibernate the problem is how

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.