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

前端 未结 2 1236
感动是毒
感动是毒 2020-12-03 11:00

In visual studio 2008, when I drag a database table into my dbml screen, any tables that end with the letter s automatcially get the s removed from the dbml object. Is ther

相关标签:
2条回答
  • 2020-12-03 11:36

    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

    0 讨论(0)
  • 2020-12-03 11:49

    In a code first scenario, you can handle some problems that pop up like this on a more granular level by simply specifying the name of the table on the entity with the Table attribute:

        [Table("QTPhotos")]
        public class QTPhoto 
    

    What I found was, originally, we had a simple entity name "Photo," but this was conflicting with some things (with a number of our entity names), so we started qualifying them ("QT" as a sample prepend), and suddenly this problem popped up. So I bet this is because "Photo" is a recognized word ending in 'o' that does not pluralize to "..oes" (as in Potatoes), but "QTPhoto" was not, meaning it was trying to find a table named "QTPhotoes".

    Simply setting the table name fixes this.

    0 讨论(0)
提交回复
热议问题