Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 ID or Id

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-08-03 : 10:34:31
Hello,

I have am using SQL Server and Entity Framework to create my Entities.

On my SQL code I have:

create table Assets
(
ID uniqueidentifier not null rowguidcol
constraint PK_Asset primary key clustered,
Content nvarchar(max) not null
) -- Assets

And my Entity becomes:

public class Asset {
public Guid ID { get; set; }
public String Content { get; set; }
}

When should I use ID or Id?

I also found the following:
http://msdn.microsoft.com/en-us/library/ms229043.aspx

I get the impression that it should be ID ... But then in Pascal it should be Id ...

I am a little bit confused. What do you usually do?

NOTE: The code I write in this post is exactly as I am using at the moment.

Thanks,
Miguel

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-03 : 10:58:05
Sql server is not case sensitive (with the default collations) so technically it doesn't matter. One problem I have with your structure is I don't like to name anything with a name so generic you can't tell what type of ID it is. I would call it [AssetsID]

Be One with the Optimizer
TG
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-08-03 : 11:47:20
quote:
One problem I have with your structure is I don't like to name anything with a name so generic you can't tell what type of ID it is. I would call it [AssetsID]



Yes, I used that.

But then on my Entity Framework Entities I started to have:
Asset.AssetId which makes not a lot of sense since I always have Asset before. Like Asset.Content represents the content of the Asset.
So Asset.ID would be more coherent with the rest of the code.

So I created the following rule for my SQL code:

ID for the PKs and GroupID, PostID, etc for FKs.


create table Tags
(
ID uniqueidentifier not null rowguidcol
constraint PK_Tag primary key clustered,
GroupID uniqueidentifier not null,
[Name] nvarchar(40) not null
) -- Tags

On the Many to Many relation ship tables I use:

PostID uniqueidentifier not null,
TagID uniqueidentifier not null,
constraint PK_PostsTags
primary key clustered (PostID, TagID),


I have seen this approach of SQL coding somewhere.

And it fits to what I described.

Does this make sense?

Thanks,
Miguel
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-03 : 12:58:59
Yes it does. It's not what I'm used to but everyone has their own preferences for these types of conventions. The best thing about what you're doing is coming up with a convention that will be consistently applied throughout the domain.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -