Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:31:30+00:00 2026-06-14T09:31:30+00:00

I am trying to figure out how to prevent Entity Framework from creating a

  • 0

I am trying to figure out how to prevent Entity Framework from creating a composite primary key on one of my tables. I have the following two entities:

public class Entry
{
   public Int64 EntryID { get; set; }
   public string UserName { get; set; }
   public string EntrySubject { get; set; }
}

public class Revision
{
   public Int64 RevisionID { get; set; }
   public string RevisionDescription { get; set; }

   public Int64 EntryID { get; set; }
   public Entry Entry { get; set; }
}

When Entity Framework generates the database, the Revisions table gets a composite primary key made up of RevisionID and EntryID. I would like the primary key for the Revisions table to be RevisionID only. Is there a way to do that? (I am using Entity Framework 4.3 with SQL Server CE, if that makes a difference.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:31:32+00:00Added an answer on June 14, 2026 at 9:31 am

    You can create a Key Data Annotation in your Revision class, to explicitly define your key:

    public class Revision
    {
       [Key]
       public Int64 RevisionID { get; set; }
       public string RevisionDescription { get; set; }
    
       public Int64 EntryID { get; set; }
       public Entry Entry { get; set; }
    }
    

    or using Fluent:

    modelBuilder.Entity<Revision>().HasKey(r=>r.RevisionID)
    

    EDIT: Added test app and diagram

    I created a test app, with a Key annotation and it created the following database, with a primary key on Revisions table with only RevisionID

    enter image description here

    Entirety of the app:

    namespace ExampleCF
    {
        public class Entry
        {
            public Int64 EntryID { get; set; }
            public string UserName { get; set; }
            public string EntrySubject { get; set; }
        }
    
        public class Revision
        {
            [Key]
            public Int64 RevisionID { get; set; }
            public string RevisionDescription { get; set; }
    
            public Int64 EntryID { get; set; }
            public Entry Entry { get; set; }
        }
    
        public class ItemContext : DbContext
        {
            public DbSet<Entry> Entrys { get; set; }
            public DbSet<Revision> Revisions { get; set; }
    
            protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
            {
    
            }
        }   
    
        class Program
        {
            public static void Main()
            {
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out a way to prevent F10 from activating the window
I'm trying to figure out a good way to prevent developers from force pushing
I am trying to figure out how I can prevent a user from killing
trying to figure out why this is happening - I have an input text
I'm trying to figure out how cookies can be used to prevent a hacker
I'm trying to figure out how to prevent session hijacking. Here's what I was
Doctrine NOOB here, trying to figure out how to prevent a duplicate record in
I'm trying to figure out how I can prevent multiple of the class asks
I am trying to figure out how to accomplish the following: Handle client-side click
I have a small hierarchy of classes and I'm trying to figure out a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.