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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:28:49+00:00 2026-06-16T19:28:49+00:00

Hi I am using Entity framework code first for the first time and I

  • 0

Hi I am using Entity framework code first for the first time and I am having trouble generating the tables.I have created an empty database in my App_Data in an MVC3 application.
This are the models I have created:

 public class Brand {
    public int BrandId { get;set; }
    public string BrandName { get;set; }
}

public class Model
{
    public int ModelId { get;set; }
    public Brand BrandId { get;set; }
    public Category CategoryId { get;set; }
    public string ModelName { get;set; }
}

public class Category
{
    public int CategoryId { get;set; }
    public string CategoryName { get;set; }
}

This is the dbContext:

public class CarsEntities : DbContext{
    public DbSet<Brand> Brands { get;set; }
    public DbSet<Model> Models { get;set; }
    public DbSet<Category> Categories {get;set;} 
}

And this is the connectionString in web.config:

<connectionStrings>
      <add name="CarsEntities" connectionString="Data Source='D:\Projects IDE\Visual Studio\MyWork\Websites\SellCars\SellCars\App_Data\Cars.sdf'" providerName="System.Data.SqlClient" />      
 </connectionStrings>

Now I have initialized CarsEntities in my HomeController but it seems that none of the tables get generated.What am I doing wrong?

  • 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-16T19:28:50+00:00Added an answer on June 16, 2026 at 7:28 pm

    I think the problem comes in your

    webcofig 
    

    here is if you want to use the db as a file like mdf file database file
    specifically in dtasource

           `<add name="CarsEntities"  connectionString="data source=.\SQLEXPRESS; Integrated
     Security=SSPI;AttachDBFilename=|yourDirectoryDirectory|\thenameofyourdb.mdf;User
     Instance=true"  providerName="System.Data.SqlClient" /`>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Entity Framework 4.1 Code First. In my entity, I have three date/time
I'm using Entity Framework Code First v 4.3.0 I have a two entities with
I am Using C# 2010 Entity framework code first If I have A class
I'm using Entity Framework 4.3 Code First with a custom database initializer like this:
I am creating a new database model using Entity Framework 4.3 Code-FIrst; using Fluent
I have a small MVC 3 app using Entity Framework Code First and use
I'm using Entity Framework 5, and a code first approach. I have a Product
I am currently using Entity Framework 4.2 with Code First. I currently have a
I successfully created my first Entity Framework Code first project using SQL Server CE.
When using Entity Framework Code First 4.3.1 it is possible to create relationships with

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.