Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinqPad adds an S to the end of every table

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

like image 540
Purplegoldfish Avatar asked Oct 20 '11 08:10

Purplegoldfish


2 Answers

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).

like image 59
Mark Byers Avatar answered Oct 20 '22 22:10

Mark Byers


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?

like image 29
StuartLC Avatar answered Oct 20 '22 21:10

StuartLC