Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Stupid Naming Consequences with LINQ

Stupid Naming Consequences with LINQ

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdatabasevisual-studiolinqquestion
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2689127
    wrote on last edited by
    #1

    Here's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like oUser = New User oUser.UserName = "John" instead of oUser = New Users This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.

    W L _ M 4 Replies Last reply
    0
    • U User 2689127

      Here's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like oUser = New User oUser.UserName = "John" instead of oUser = New Users This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.

      W Offline
      W Offline
      whatrevolution
      wrote on last edited by
      #2

      This reminds me of, "automagically", in the Buzzwords Hall of Shame, and makes me wish you didn't like the feature; because auto-complete is good, but auto-editorialize is nonsense and dangerous, as you just illustrated. Programming != Word Processing. X|

      Honestly Illustrated

      <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

      1 Reply Last reply
      0
      • U User 2689127

        Here's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like oUser = New User oUser.UserName = "John" instead of oUser = New Users This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Had a similar problem few months ago. I had "Language" table in database basically storing all languages, that were used for multi-language stuff. Then when database schema was finished, I began working on data access layer and DataSet designer failed miserably on that "Language" table. I don't recall what the problem was exactly, but the "Language" name was a no-no. Cheers

        1 Reply Last reply
        0
        • U User 2689127

          Here's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like oUser = New User oUser.UserName = "John" instead of oUser = New Users This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.

          _ Offline
          _ Offline
          _beauw_
          wrote on last edited by
          #4

          I really do not think that the Object/Relational Designer should do any such renaming. I understand the rationale behind recommending that these names be singular, but it is not the place of the Object/Relational Designer to enforce this. This is the sort of thing that drives programmers away from the IDE "power tools" and I think this is a shame.

          D H 2 Replies Last reply
          0
          • _ _beauw_

            I really do not think that the Object/Relational Designer should do any such renaming. I understand the rationale behind recommending that these names be singular, but it is not the place of the Object/Relational Designer to enforce this. This is the sort of thing that drives programmers away from the IDE "power tools" and I think this is a shame.

            D Offline
            D Offline
            David Skelly
            wrote on last edited by
            #5

            I may be wrong but I think there is an option to turn this "pluralization" behaviour off.

            W 1 Reply Last reply
            0
            • D David Skelly

              I may be wrong but I think there is an option to turn this "pluralization" behaviour off.

              W Offline
              W Offline
              whatrevolution
              wrote on last edited by
              #6

              I think it should be an option to turn the feature on.

              Honestly Illustrated

              <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E

              1 Reply Last reply
              0
              • U User 2689127

                Here's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like oUser = New User oUser.UserName = "John" instead of oUser = New Users This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.

                M Offline
                M Offline
                Marcelo Ricardo de Oliveira
                wrote on last edited by
                #7

                I once had this bad experience too, and at that time we noticed that having database tables with Portuguese names would solve the problem (although we might have had problems with pluralization/singularization...)

                Take a look at Soccerlight World Cup 2010 here in Code Project.

                1 Reply Last reply
                0
                • _ _beauw_

                  I really do not think that the Object/Relational Designer should do any such renaming. I understand the rationale behind recommending that these names be singular, but it is not the place of the Object/Relational Designer to enforce this. This is the sort of thing that drives programmers away from the IDE "power tools" and I think this is a shame.

                  H Offline
                  H Offline
                  Hired Mind
                  wrote on last edited by
                  #8

                  _beauw_ wrote:

                  but it is not the place of the Object/Relational Designer to enforce this.

                  That's why you can disable it: Model IDE->Properties->Pluralize New Objects Please note that this is a pure religious issue: In my case, all my tables are singular names(Login, Person, Role, etc). So I would have had a table named "System" and without the pluralization on, I would have had to map them differently to avoid this collision. You can map the tables any way you like in EF4. Fact is, you'll always run the risk of name collisions with any code generation.

                  Before .NET 4.0, object Universe = NULL;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups