Last post Dec 06, 2012 08:36 PM by CruzerB
Dec 06, 2012 07:38 PM|3v3rhart|LINK
What does the difference bewteen the use of "Album" (capital 'A') and "album" (lower-case 'a') and "Albums" (capital 'A' / plural 's') indicate in the code below?
Album album = db.Albums.Find(id);
Dec 06, 2012 07:49 PM|CPrakash82|LINK
Is a list of entity album, basically a collection from database or db context.
is a single item in the list, which is getting retrieved by the id.
Dec 06, 2012 08:35 PM|Paul Linton|LINK
C# is a case sensitive language. This means that there is no relationship at all between
So, to answer your question directly, the difference indicates that they are totally separate things as far as C# is concerned.
However, the programmer has probably chosen those names to be similar because they are referring to similar things. It is quite normal to have a class (particularly if it is public) start its name with an uppercase letter - hence Album is a class. It is
also quite common, but a little confusing, to have a private instance of that class be named with a lowercase first letter. So, many programmers would guess that 'album' is an instance of the class 'Album'. This is not a rule of C# it is just a convention
that many programmers follow.
Similarly, a common convention is to use a plural name if you have a collection of something. In this case using the name Albums to hint to other programmers that this represents a collection of Album objects.
For what it is worth, I generally try to avoid the naming an instance by just making the first letter lowercase. So normally I would write the first line of your sample
Album obsoleteAlbum = db.Albums.Find(id);
all this does for me is that later in the code when I see the variable obsoleteAlbum I have a much better idea of guessing what the variable refers to than if I just gave it the simple name of album.
Dec 06, 2012 08:36 PM|CruzerB|LINK
Album is a DataType.
album is a variable as Album
Albums is a collection of album data. You got this because you were enabled the "Pluralize or singularize generated object names" during entity model creation. You can refer to http://www.danrigsby.com/blog/index.php/2009/05/19/entity-framework-40-pluralization/