Linq to SQL,表名以"es"结尾创建错误的实体类名称 [英] Linq to SQL with table name ending in "es" creates wrong entity class name

查看:92
本文介绍了Linq to SQL,表名以"es"结尾创建错误的实体类名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SQL表名称都是复数形式-事件,团队,校园等... 当我将表拖入dbml时,它会创建一个名为"校园"的实体,这当然是不正确的.我在属性页中手动将其重命名为 Campus ,但它似乎无法正确更新所有自动生成的代码.例如,.designer.cs文件具有以下代码:

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

应该在什么时候

    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?

推荐答案

您可以

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.

这篇关于Linq to SQL,表名以"es"结尾创建错误的实体类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆