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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:01:50+00:00 2026-05-23T18:01:50+00:00

I’m investigating replacing or supplementing our home grown ORM system with the Entity Framework

  • 0

I’m investigating replacing or supplementing our home grown ORM system with the Entity Framework 4, and I’m noticing that the latter may end up causing a conflict between what we’ve defined as the naming conventions for our programming code and our databases. Being a Microsoft shop, we’ve largely decided to follow Microsoft’s naming guidelines for our code, which say to use Pascal casing for members, namespaces, etc.; to avoid using underscores, and so on.

The default entity naming conventions in EF4, not surprisingly, work great with these standards. For example, an entity named SalesOrder will generate a class named SalesOrder and an entity set named SalesOrders. An EF4 Model-First design will, by default, generate a table of the same name as the entity set (in this example, the generated table name is SalesOrders). However, our database standards suggest to use all lowercase and underscores between words (e.g., sales_orders). So, using the Entity Framework “as is” will cause us to start deviating from them.

Is there anywhere in the Entity Framework where you can override it’s behavior to use the entity set name as the SQL table name? I can’t seem to find an obvious place to specify an alternate table name for the generated SQL script. If we go forward with using EF4, is the only plausible solution to have us reconsider our database naming conventions?

Update:

I’m trying Ladislav’s solution below, but I can’t seem to get the Generate Database from Model option in the Entity Framework model designer to recognize my custom utility. I have a file named MyOrg.EF.Utility.CS.ttinclude in the folder:

%VSINSTALLDIR%\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

It essentially looks like this:

<#@ import namespace="Microsoft.CSharp"#>
<#@ import namespace="System.Text"#>


public class CustomUtilities
{
    public static string EntityNameToSqlName(string name)
    {
        string sqlName = "";    // The table name based on the input model name
        string pattern = "([A-Z]+[s])|([A-Z](?=[a-z]))|((?<=[a-z])[A-Z])";  //Pattern for the regex exp. below

        // Separate out each word with spaces:
        sqlName = System.Text.RegularExpressions.Regex.Replace(name, pattern, " $&");

        // Replace spaces with underscores and then make lowercase:
        sqlName = sqlName.Trim().Replace(" ", "_").ToLower();

        return sqlName;
    }

}

I’ve tried to reference this file in my custom .tt DDL generation file near the top as such:

<#@ include file="MyOrg.EF.Utility.CS.ttinclude"#>

However, if I try to reference the above function using code like this in the .tt file:

string tableName = CustomUtilities.EntityNameToSqlName(Id(entitySet.GetTableName()));

Visual Studio then complains that The name ‘CustomUtilities’ does not exist in the current context. Removing the class name from “CustomUtilities.EntityNameToSqlName” returns a similar error. Should I try a different way to insert a custom function into the DDL generation code?

Final solution:

I was able to finally get this working after I realized that I didn’t wrap the C# code in my MyOrg.EF.Utility.CS.ttinclude file with this:

<#+
[my code]
#>

I also needed to add a public copy of the WriteColumns() method found in the file GenerateTSQL.Utility so that it would use my EntityNametoSqlName() method.

Unfortunately, my customized version of the original SSDLToSQL10.tt file is now a little messy, since I need to wrap CustomUtilities.EntityNameToSqlName() around quite a few items in there.

  • 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-23T18:01:51+00:00Added an answer on May 23, 2026 at 6:01 pm

    Sure there is. There is T4 template which converts your model to SQL DDL scripts. You can make a copy of this template and put your own logic for name generation into the new copy. After that you just need to set this template in your designer (DDL Generation Template property) and run Generate Database from Model …

    You will find default template in:

    %VSINSTALLDIR%\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToSQL10.tt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.