非常有用的两篇文章

MSDN:Code First 迁移

博客园:CodeFirst数据迁移(不丢失数据库原有数据)

 

 

EF有三种开发模式:Model First,Database First 和 Code First。 本文主要介绍Code First模式,Code First即代码优先,就是先编写业务实体模型类,然后通过程序包管理器控制台创建数据库。

  在项目上右键菜单,点击“管理NuGet程序包”,搜索“EntityFramework”,在项目中安装最新版本的EntityFramework。

  代码优先-Code First

  代码优先-Code First

二、修改配置文件

EntityFramework安装完成后,会自动生成一个App.confing文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>
View Code

相关文章: