-->

Linq to SQL with table name ending in “es” creates

2019-08-01 19:08发布

问题:

My SQL tables names are all plural - Events, Teams, Campuses, etc... When I drag the tables in to the dbml, it creates an entity called "Campuse" which of course is incorrect. I manually rename that to Campus in the properties page, but it doesnt seem to update all of the auto generated code correctly. For example, the .designer.cs file has the following code:

    public System.Data.Linq.Table<Campus> Campus

when it should be

    public System.Data.Linq.Table<Campus> Campuses

Similar problems with association names.

I could probably go through all of that generated code, and try to rename everything manually, but that's a pain. Is there a better way?

回答1:

You can turn off automatic pluralization of LINQ-to-SQL entities, and that should correct your problem. Unfortunately, LINQ-to-SQL (and the Entity Framework) are designed to work with the much more prevalent practice of naming tables in singular form. The code generator will try to figure out the singular form of what it sees as a plural word, but it's not particularly adept at this task.