表名以“es”结尾的 Linq to SQL创建错误的实体类名称
我的 SQL 表名称都是复数 - Events、Teams、Campuses 等... 当我将表拖入 dbml 时,它会创建一个名为“Campuse”的实体,这当然是不正确的。我在属性页面中手动将其重命名为 Campus,但它似乎没有正确更新所有自动生成的代码。例如,.designer.cs 文件有以下代码:
public System.Data.Linq.Table<Campus> Campus
当它应该
public System.Data.Linq.Table<Campus> Campuses
与关联名称类似的问题时。
我可能可以浏览所有生成的代码,并尝试手动重命名所有内容,但这很痛苦。有更好的办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以 关闭 LINQ-to-SQL 实体的自动复数化,这应该可以解决您的问题。不幸的是,LINQ-to-SQL(和实体框架)旨在与以单数形式命名表的更流行的做法配合使用。代码生成器将尝试找出它所认为的复数单词的单数形式,但它并不是特别擅长这项任务。
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.