LinqPad adds an S to the end of every table

穿精又带淫゛_ 提交于 2019-12-06 23:41:23

问题


I have just downloaded LinqPad to explore the benefits of using Linq queries in an application I am working on, however when I look at my database tables in the column on the left LinqPad displays all my tables with an 's' on the end, for instance CategoryTbl becomes CategoryTbls yet when I view my database in SQL management studio the table names appear correct.

Though any tables that should have an S on the end ie clients remain unchanged.

When I execute a Linq query I have to execute it against CategoryTbls but a SQL query has to be executed against CategoryTbl.

I was just wondering why this has happened, is it a bug or a feature? and if it is a feature why?

Thanks


回答1:


The first question from the LINQPad FAQ:

Why does LINQPad pluralize table and child association properties? Can I switch this off?

Pluralizing child association properties (while keeping parent associations singular) makes for the most natural queries and is what Visual Studio does by default in building typed DataContexts.

To switch off pluralization, uncheck the "Pluralize" option when adding the database connection. (If the connection has already been created, right-click it to edit the connection properties).




回答2:


This is also the standard behaviour of LINQ2SQL generated artifacts - the IEnumerables on the DataContext are [TableName]s and the Entity is [TableName]. So your linq queries would typically be something like.

List<Category> categoryList = context.Categories.Where(cat => somePredicateOnCat).ToList();

This usually makes for intuitive reading. Would you consider dropping the Hungarian 'tbl' suffix off your table naming standards?



来源:https://stackoverflow.com/questions/7833133/linqpad-adds-an-s-to-the-end-of-every-table

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