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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:09:27+00:00 2026-06-15T21:09:27+00:00

I’m using EF5 Code First, I have entities named XXXEntity which is based on

  • 0

I’m using EF5 Code First, I have entities named XXXEntity which is based on Entity class, in Entity class there is Id property.

Here is the problem, normaly EF will create table for each entity named XXXEntities and having Id field. What I want is the table should named XXX (without Entities) and the Id should be XXXId. How to do that at once by using convention. I know I can override the table name, and Id name one by one. But it is a bit boring and not reusable, is there any better way to do that using convention or something on EF 5?

UPDATE

i read about custom code first conventions but not sure is this an out dated page or a non implemented feature. because i couldn’t found the Properties<T>() method on EF 5

  • 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-15T21:09:28+00:00Added an answer on June 15, 2026 at 9:09 pm

    No, you can’t do that with EF 5, your link is a future feature for EF 6 see here

    but you can do that with reflection easily, for reusability you can make it as an extension method of DbModelBuilder, a bit slow but it solve your case. here what you can do:

    public static class MyCustomNamingConvention
    {
        public static void ToMyDatabaseNamingConvention(
            this DbModelBuilder mb, IEnumerable<Type> entities)
        {
            foreach (var entity in entities)
            {
                var mi = typeof(MyCustomNamingConvention)
                    .GetMethod("MyNamingConvention")
                    .MakeGenericMethod(entity);
                mi.Invoke(null, new object[] { mb });
            }
        }
    
        public static void MyNamingConvention<T>
            (DbModelBuilder mb) where T : Entity
        {
            var tableName = typeof(T).Name.Replace("Entity", "");
            mb.Entity<T>().HasKey(x => x.Id);
            mb.Entity<T>().Property(x => x.Id).HasColumnName(tableName + "Id");
            mb.Entity<T>().ToTable(tableName);
        }
    
    }
    

    Simply use it on your DBContext on OnModelCreating method

    protected override void OnModelCreating(DbModelBuilder mb)
    {
        base.OnModelCreating(mb);
        mb.ToMyDatabaseNamingConvention(GetEntities());
    }
    

    Note:

    • Remember to add appropriate namespace of the
      MyCustomNamingConvention.
    • GetEntities() is a method to iterate your entity (remember to skip
      the Entity base class)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a small JavaScript validation script that validates inputs based on Regex. I
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.