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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:25:27+00:00 2026-05-17T17:25:27+00:00

i’m using oracle with FluentNHibernate automapping with alterations & NHibernate the problem is how

  • 0

i’m using oracle with FluentNHibernate automapping with alterations & NHibernate
the problem is how to specify the constraint name by overriding the mapping model??

the generated sql like this:

alter table FirstTable
    add constraint FK_VerLongIdentifierLongerThan30Characther
    foreign key (FirstTableID) 
    references SecondTable;

i need to change the “FK_VerLongIdentifierLongerThan30Characther” to smaller identifier by overriding the mapping model like this:

model.Override<SomeClass>(m =>
    {
        m.HasOne<SomeOtherClass>(c => c.SomeProperty).?????????;
        //or
        m.????????
    }
  )
  • 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-17T17:25:27+00:00Added an answer on May 17, 2026 at 5:25 pm

    Instead of doing an override for each class with this problem, what I have done is create a mapping convention which would truncate objects with surpass a 30-character naming scheme on foreign keys, has many and many to many relations:


    public class OracleIHasManyConvention : IHasManyConvention
    {
        public void Apply(IOneToManyCollectionInstance instance)
        {
            var keyName = string.Format(CultureInfo.InvariantCulture, "FK_{0}_{1}",
                                        instance.Member.Name,
                                        instance.EntityType.Name).Truncate(30);
    
            instance.Key.ForeignKey(keyName);
        }
    }
    

    public class OracleForeignKeyConvention : FluentNHibernate.Conventions.ForeignKeyConvention
    {
        protected override string GetKeyName(Member property, System.Type type)
        {
            var name = property == null
                       ? "Id_" + type.Name.ToUnderscoredNaming()
                       : "Id_" + property.Name.ToUnderscoredNaming();
    
            return name.Truncate(30);
        }
    }
    

    Then I would call these conventions like this:

    var cfg = Fluently.Configure()
                    .Database(SQLiteConfiguration.Standard.UsingFile("foobar.lite3"))
                    .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Product>()
                                                          .Where(a => a.Namespace == typeof (Product).Namespace)
                                                          .Conventions.Add<OracleIHasManyConvention>()
                                                          .Conventions.Add<OracleForeignKeyConvention>()
                                                          .Conventions.Add<OracleGeneralConvention>()
                                                          .Conventions.Add<CascadeAllConvention>()
                                       ));
    

    Here’s the Truncate extension:

    public static class StringHelper
    {
        public static string Truncate(this string text, int endIndex)
        {
            if (text.Length > endIndex)
            {
                text = text.Substring(0, endIndex).TrimEnd('_');
            }
            return text;
        }
    }
    

    I hope this is useful in any way. 🙂

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

Sidebar

Related Questions

No related questions found

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.