views:

66

answers:

2

For example, my table name is "Diagnosis". When I bring it into my LINQ to SQL model, it tries to figure out how to pluralize it, and it mistakenly assumes the entity name should be "Diagnosi" and the set name should be "Diagnosis", which could be confusing.

When I change the entity name to "Diagnosis" in the properties, it doesn't change the set name, so now they are both "Diagnosis", which is even more confusing.

Ideally, I'd like to have control over the set name and change it to "Diagnoses". I'd settle for LINQ blindly applying its pluralization and coming up with something like "Diagnosises" or something. Any ideas?

A: 

I don't know of a good way to do this, but here are some ideas:

  • if you don't have to round-trip you model too much, you can override the class names in the generated XML (right click on the DBML, edit in XML editor).
  • you can try to place this one class into a separate model and run SQLMetal manually for it, not from the VS designer (it runs implicitly when you save the model from the designer). I think you can turn off pluralization with a command line option.
  • you can derive from the wrongly named class and give it the correct name, to hide the problem from the developer
cdonner
+1  A: 

As far as I know, you can change the names of tables.

Open up the designer and click the table you want to change. Click again on the table name and it should allow you to rename it. This will not rename the actual database table, to the best of my knowledge, just your entity.

The same information appears in the properties window if you right-click a table and select Properties. You should be able to change the name of the entity which maps to your table there as well.

Ed Altorfer
Yes, the table can be renamed, but LINQ uses an algorithm to figure out the collection name. If your physical table name was "Authors", LINQ tries to help by naming the entity "Author" and naming the collection "Authors". In the case of "Diagnosis", it mistakenly removes the "s" thinking this is a plural form of "Diagnosi". When I rename the table back to "Diagnosis", the algorithm still calls the collection "Diagnosis". I want control over the collection name.
gfrizzle
You can try changing the name manually. :)
Ed Altorfer