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 8022789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:22:19+00:00 2026-06-04T22:22:19+00:00

I am trying to create an sdf with Code-First, however I am getting an

  • 0

I am trying to create an sdf with Code-First, however I am getting an error that no Keys are defined for my tables, and cannot understand why.

I have the following Classes :-

public class Article
{
    [Key]
    public int ArticleID;

    //[Display(Name = "Title")]
    //[MaxLength(255)]
    //[Required(ErrorMessage="Title is required")]
    public string ArticleTitle;

    //[Display(Name = "Date")]
    //[DisplayFormat(DataFormatString = "{0:#.#}", ApplyFormatInEditMode = true, NullDisplayText = "")]
    //[Required(ErrorMessage = "Date is required")]
    public DateTime ArticleDate;

    //[Display(Name = "Text")]
    //[Required(ErrorMessage = "Text is required")]
    public string ArticleText;

    //[Display(Name = "Source")]
    public string ArticleSource;

    //[Display(Name = "Category")]
    public int CategoryID { get; set; }

    public virtual Category Category { get; set; }

}

public class Category
{
    [Key]
    public int CategoryID;

    [Display(Name = "Category Title")]
    [MaxLength(255)]
    [Required(ErrorMessage = "Category Title is required")]
    public string CategoryTitle;

}

public class CommonsContext : DbContext
{
    public DbSet<Article> Articles { get; set; }
    public DbSet<Category> Categories { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        //A one-to-one relationship between the Article and Category tables. 
        modelBuilder.Entity<Article>().HasRequired(x => x.Category);
    }

}

and in the web.config :-

<add name="CommonsContext" connectionString="Data Source=|DataDirectory|Personal.sdf" providerName="System.Data.SqlServerCe.4.0" />

When I browse to the App_Data folder, I cannot even see the Personal.sdf, so it means that its not even created.

What am I doing wrong? Can’t figure out as yet.

Thanks for your help and time

  • 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-04T22:22:21+00:00Added an answer on June 4, 2026 at 10:22 pm

    Probably because you haven’t defined getters and setters for your key properties

    public int ArticleID { get; set; }
    
    public int CategoryID { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a gui using Tkinter that grabs a username and password and
Trying to create a prayer time app for prayertimes in Oslo. I have a
Trying to create a regex pattern for email address check. That will allow a
I have been using Entity Framework CTP with Code-First as in this tutorial by
I am trying to create a method that counts the number of each full
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying create a box in my Django app that displays text (and possibly
I'm trying create a ASMX webservice that can perform a HTTP GET request. I
I have am trying to create some integration tests with no external database dependencies
I am trying create a small web application that allows a user to login

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.