Why does "linq to sql classes" change the name of the table when creating the class?

I went in and added the new "linq to sql" classes in Visual Studio, and then drag the table from Database Explorer to the new DBML, and the name of the new class will no longer be multiple. What if I still want it to be plural? If I drag a table that is not multiple, I get a bunch of compilation errors about how a type definition already exists for all the fields in the table that I put in the dbml layout. If I then make the class name plural for a table that was not plural in the dbml layout, clicking the name and changing it will no longer compile the errors.

+2
source share
2 answers

You can click on the table name in the dbml table and rename it. Or you can select a table in DBML and go to the properties window. There you can change the name and table to which it connects.

One way to avoid name clashes is to designate namespaces accordingly. For example, you can put your DBML file in a subfolder in your project and assign it something like DataAccess. Therefore, when comparing with the Ling2Sql class, you should use DataAccess.Customer, and you can avoid a conflict with the Client, because he lives somewhere else.

As a tidbit, Linq2Sql by default makes tables not multiple. This is based on convention. For example, in the customer table there are many customers. When you create an instance of an object, you look at one Client, not a table. The object is essentially displayed in a row in the Customers table, so it becomes the only one.

+6
source

I just realized what was going on. After the suggestion “move it to a new folder”, I tried this and it worked. But there was no point in why this worked, because if there were conflicts of the type, the new folder should have had the same conflicts, but I didn’t have a single problem that I had before, and I could rename everything that I wanted after moving to a new folder and there were no conflicts. Renaming things after dragging and dropping is a bad idea because if the database schema changes and you want to update your classes, you have to drag the table back and then manually make the changes again.

ANYWAY, the problem is that before I did the "linq to sql classes", I created the "ADO.NET Entity Data Model". What caused all the names is in conflict. But the offer to move to a new folder was awesome and led me to a final decision!

0
source

All Articles