azure sql server, table name with s

sum eric 21 Reputation points
2021-07-19T14:23:52.707+00:00

Dear Sir,

I use visual studio 2019. c#
I study project "Tutorial: ASP.NET app with Azure SQL Database - Azure "
I download DotNetAppSqlDb.

I change Table name from "Todoes" to "Unit" in the project.
But in the azure server, character "s" is added to Unit by the system.
Table name in Azure server is Units.
But I can not see table name "Units" in the project code.
It seems "s" is added to table name automatically.

I try another project and try to use table name "customer", But "s" is added by system automatically. So the result table name is "customers".

Can I use table name with no "s"?
Do I miss to see something in the project code?

Thank you
Eric

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Anurag Sharma 17,631 Reputation points
    2021-07-20T07:26:52.537+00:00

    Hi @sum eric , welcome to Microsoft Q&A forum.

    Entity Framework pluralize the table names in Code first approach. However you can override this behavior by many ways. One of the way is to add the below code in the myDatabaseContext.cs class in your project as below:

     public System.Data.Entity.DbSet<DotNetAppSqlDb.Models.Todo> Todoes { get; set; }  
      
            protected override void OnModelCreating(DbModelBuilder modelBuilder)  
            {  
                modelBuilder.Entity<Todo>().ToTable("Todo");  
            }  
    

    Referenced Article:

    Entity Framework added s to my .dbo

    Please let me know if this helps or else we can discuss further.

    ----------

    If answer helps, you can mark it 'Accept Answer'

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.