Entity Framework and Primary Key (ID)

Last post 07-30-2009 1:56 AM by Wencui Qian - MSFT. 1 replies.

Sort Posts:

  • Entity Framework and Primary Key (ID)

    07-27-2009, 2:35 PM
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Hello,

    I am starting using Entity Framework and I have the following SQL tables:

    create table Tags
    (
      TagID uniqueidentifier not null
        constraint PK_Tag primary key clustered,
      [Name] nvarchar(100) null
    ) -- Tags
    
    -- Articles
    create table Articles
    (
      ArticleID uniqueidentifier not null
        constraint PK_Article primary key clustered,
      Body nvarchar(max) null,
      Created datetime null,   
      Excerpt nvarchar(max) null,
      Published bit null,   
      Title nvarchar(400) null,
      Updated datetime null
    ) -- Articles
    
      -- ArticleTags
      create table ArticleTags
      (
        ArticleID uniqueidentifier not null,
        TagID uniqueidentifier not null,
          constraint PK_ArticleTags
            primary key clustered (ArticleID, TagID),
          constraint FK_ArticleTags_Articles
            foreign key(ArticleID)
            references Articles(ArticleID)
            on delete cascade,
          constraint FK_ArticleTags_Tags
            foreign key(TagID)
            references Tags(TagID)
            on delete cascade
        ) -- ArticleTags


    The problem with my code is when I create the Entities I get for each entity ArticleID and TagID instead of only ID.

    I checked the following example and this case the author get ID in all primary keys of all entities:
    http://msdn.microsoft.com/en-us/data/cc546556.aspx

    Could you tell me how to change my code to accomplish that?

    And is there something I should change on my code?

    Should I remove the delete cascade and take care of that on my repositories?

    Thanks,
    Miguel

  • Re: Entity Framework and Primary Key (ID)

    07-30-2009, 1:56 AM
    Answer

    Hi shapper,

    For questions of ADO.NET Entity Framework and LINQ to Entities, you could post them here to get better and quicker responses.

    Thanks.

    David Qian
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)