Linq to SQL: How to Stop the Auto Generated Object Name from Being Renamed

Linq to SQL: How do I stop the auto generated object name from being renamed?

You need to disable the Pluralize Table Names for the LINQ to SQL designer.

To do this navigate to Tools -> Options -> Database Tools -> O/R Designer and change the Pluralization of names to false.

Then you will need to recompile your project and it should address the naming

Stop LINQ to SQL from Renaming properties of the DataContext after I rename them

When you make a change to the data model dbml file, the Linq to SQL classes are generated completely from scratch. Any modifications you make to the class files will be overwritten.

Changing the pluralization rules would have to be done by changing the code generation, but I do not know if this is possible.


You can change the generated name by right-clicking the table in the dbml designer window and selecting properties. There is a field called 'name' with which you should be able to define a custom name.

Also: this is not directly relevant to this particular issue, but if you want to add modifications to the generated classes, they are defined as partial classes. So you could add methods to the classes by creating a separate partial class.

Why does linq to sql classes change the name of a table when making a class?

You can single click on the tablename in the dbml table and rename it. Or you can select the table in the DBML and go to the properties window. There you can change the name, and the table it hooks up to.

One way to avoid the name conflict is to designate namespaces accordingly. For example, you can place your DBML file in a subfolder in your project and assign it something like DataAccess. Therefore, when you map to the Ling2Sql class, you'd do DataAccess.Customer and you can avoid the conflict with Customer, since it lives somewhere else.

As a tidbit, Linq2Sql by default makes tables non-plural. It's based off of a convention. For example, a table Customers has many customers. When you instantiate an object, you're looking at a single Customer, not the table. The object is essentially being mapped to a row in the Customers table, thus it becomes singular.

How to disable removal of the letter s when importing a table in LINQ to SQL?

You should disable pluralization of names for O/R Designer. You can disable it in Tools > Options > Database Tools > O/R Designer settings:

O/R Designer Settings

Now when you'll drag some table from server explorer to design surface, name pluralization will be turned off and you'll get entity name equal to database table name.

Note: I don't recommend you to turn off pluralization, because entity names in plural form are confusing.

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

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.

How to prevent Visual Studio 2012 from renaming member types (using Entity Framework)?

Thats a very common problem with auto generated code and classes that match a namespace name (windows designer does re add the full qualified name as well every time you change something in the designer), just rename the class and save a lot of time.

Property name repeated but with different data type

It's not a repeated property - it's two different properties for two different purposes.

The Vendor property corresponds to the data in the column in your database.

The Vendor1 property represents the foreign key relation, i.e. the join to another table. It's called Vendor1 because the name Vendor was already taken (using VendorId for the column name is a good idea). The Vendor1 object won't be fetched by default unless you actually use it. Having this property available makes it easier to formulate queries that would otherwise require you to specify a join.

Both properties are useful to have on your object.


To answer your updated question:

Linq has to fetch the vendor id anyway whether you use it or not - just in case you might use it. Since it has already been fetched it seems convenient that it is also visible in the interface. If you wrote obj.Vendor1.Id instead of obj.VendorId, it would cause the Vendor1 object to be fetched from the database unnecessarily. So there is also a performance implication.

Visual Studio dropping 's' off of sql server tables

If you are using entity framework, and adding tables via the update wizard, there is a checkbox which says "Pluralize or singularize generated object names":

update wizard

You can uncheck that and it will leave your table names alone.

Update: looks like you are drag/dropping to DBML, try this link:

Linq to SQL: How do I stop the auto generated object name from being renamed?



Related Topics



Leave a reply



Submit