Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Entity Framework Basics Extending Our Entity Data Model Overriding the Context's OnModelCreating Method

saikiran maddukuri
saikiran maddukuri
17,919 Points

i don't get it!!!

what is the use of Pluralizing Table Name Convention you said in this video James Churchill To check the documentations but it didn't helped me in understanding the use of removing can you please explain with example so that i can clearly notice the difference between Removed Pluralizing Table Name Convention and Added Pluralizing Table Name Convention

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

1 Answer

Allan Clark
Allan Clark
10,810 Points

By default, when creating the tables, Entity Framework will use the plural form of the EF objects. For example if I had the EF objects ComicBook, Illustrator, and Author the corresponding table names would be ComicBooks, Illustrators, and Authors. This is done because the class defined in code represents a single Entity, and the table in the db represents a collection of those Entities.

Removing the PluralizingTableNameConvention simply prevents this default behavior. Using the same example as before, the corresponding table names would be ComicBook, Illustrator, and Author.

As far as practical use goes, it is mainly personal preference. The only reason I can think of you would need to remove the convention would be to adhere to naming standards for whatever job/project you are working on.