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

不问归期 提交于 2019-12-11 06:29:17

问题


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.



来源:https://stackoverflow.com/questions/1794872/linq-to-sql-with-table-name-ending-in-es-creates-wrong-entity-class-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!