简体   繁体   中英

Using Entity Framework Code First Development, can I get it to create a table or tables in an existing database?

I'm new to Entity Framework, and I have an existing database that I'd like to add a few tables to, rather than creating a database from scratch for my new tables. Is this possible with Entity Framework?

I've looked through the following MSDN articles on Code First development, and haven't been able to find the answer to my issue:

Code First Development

Code First Conventions

Code First Fluent API

Code First Data Annotations

I have had the same experience with my asp.net mvc3 project, it's a little different from asp.net but I guess entity framework is the focus here.

  1. create new table in sql server

  2. create corresponding model in your model project

  3. Add the new table object property in DbNameEntities.cs

    public DbSet NewTables { get; set; }

  4. In Application_Start() method, comment out the original code first approach

    System.Data.Entity.Database.SetInitializer(new SeedSampleData());

replace with this:

System.Data.Entity.Database.SetInitializer<DbNameEntities>(null);

Yes, this is certainly possible.

A decent walk-through is available on Scott Gu's blog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM