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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:35:29+00:00 2026-05-16T18:35:29+00:00

My entity name is "Contact" and my table name is "Contact". However, the default

  • 0

My entity name is "Contact" and my table name is "Contact". However, the default pluralization support is making EF4 to look for a table named "Contacts". Anybody has any idea on how to turn off the pluralization support?

This post has got some details on pluralization support. But still does not give me an answer.

I see the following text in this post. First of all, I dont know which physical .tt file I need to make this change. Also, I want to have this feature turned off only for one app and not for all.

The code generator in T4 Toolbox has
the pluralization turned on by default
in Visual Studio 2010. If you need to
generate the DAL without
pluralization, perhaps for
compatibility reasons, you can turn
this option off by adding the
following line to the .tt file before
generator.Run() method is called.

C#
generator.Pluralize = false;

VB
generator.Pluralize = False

UPDATE

Following is the code I use and I get an error given below:-

Contact

 public class Contact
 {
 public int ContactID { get; set; }
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public string Title { get; set; }
 public DateTime AddDate { get; set; }
 public DateTime ModifiedDate { get; set; }
 }

Context:-

 public class AddressBook : DbContext
 {
 public DbSet<Contact> Contact { get; set; }

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
  modelBuilder.Entity<Contact>().MapSingleType().ToTable("dbo.Contact");
 }

}

The main program:-

using (var context = new AddressBook())
  {
   var contact = new Contact
   {
   ContactID = 10000,
   FirstName = "Brian",
   LastName = "Lara",
   ModifiedDate = DateTime.Now,
   AddDate = DateTime.Now,
   Title = "Mr."

   };
   context.Contact.Add(contact);
   int result = context.SaveChanges();
   Console.WriteLine("Result :- " + result.ToString());

  }

And I get the following error on "context.Contact.Add(contact);":-

System.InvalidOperationException: The
model backing the ‘AddressBook’
context has changed since the database
was created. Either manually
delete/update the database, or call
Database.SetInitializer with an
IDatabaseInitializer instance. For
example, the
RecreateDatabaseIfModelChanges
strategy will automatically delete and
recreate the database, and optionally
seed it with new data. at
System.Data.Entity.Infrastructure.CreateDatabaseOnlyIfNotExists1.InitializeDatabase(TContext context) at System.Data.Entity.Infrastructure.Database.Initialize() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.EfInternalQuery1.Initialize()
at
System.Data.Entity.DbSet1.ActOnSet(Action action,EntityState newState, TEntity entity) at System.Data.Entity.DbSet1.Add(TEntity
entity) at
CodeFirst.Client.Program.Main(String[]
args) in E:\Ashish\Research\VS
Solutions\EntityFramework\CodeFirstApproach_EF_CTP4\CodeFirst.Client\Program.cs:line 35

I am sure I am making a stupid mistake somewhere, just unable to figure out. Could somebody please provide some directions?

ANSWER
With Pault’s help I described this problem and the solution here.

  • 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-16T18:35:29+00:00Added an answer on May 16, 2026 at 6:35 pm

    I’m adding yet a third answer as my understanding of the question changes… is that bad of me? 😉

    Like I said in my comment, I’m still learning and I haven’t attempted this with an existing database yet. That said, hopefully one of these will help:

    The post I mentioned by Scott Guthrie (http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx) has a comment by a certain Jeff that says this can help (I recommend reading the full comment as he explains in more detail):

    Database.SetInitializer<AddressBook>(null); //AddressBook being the context
    

    I’ve also happened across a comment by Rowan Miller underneath this post (http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4announcement.aspx?PageIndex=2) in the recent past. He suggests this may be an option:

    public class ProductContext : DbContext
    {
       protected override void OnModelCreating(ModelBuilder modelBuilder)
       {
           modelBuilder.IncludeMetadataInDatabase = false;
       }
       ...
    }
    

    Hopefully one of these gets you on the right track.

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

Sidebar

Related Questions

I have two entities // All details has been removed @Entity @Table(name = "A_TABLE_NAME")
Using JPA and Hibernate I have an entity class @Entity @Table(name = "ROLES") public
@Entity @Table(name = BOOKTEST) @NamedQueries({@NamedQuery(name = Booktest.findAll, query = SELECT b FROM Booktest b),
Consider the following code: @Entity @Table(name = a) public class A implements Serializable {
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
We are trying to use a basic @OneToMany relationship: @Entity @Table(name = PARENT_MESSAGE) public
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have the following tables Entity id,name,categoryid 21,Blah,1 EntityCategory (Enum table) id, name 1,New

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.