GithubHelp home page GithubHelp logo

entityframework-migrations's Introduction

Entity Framework 6 Migrations for ASP.NET 5

  1. Include the myget feed for this package, https://www.myget.org/F/atquin, or in global.json add the src directory of this repo to your projects list.
  2. Reference Atquin.EntityFramework.Migrations in your DataContext xproj;
   "dependencies": {
   	"EntityFramework6.Npgsql": "3.0.3", <!-- if you want npgsql -->
   	"Atquin.EntityFramework.Migrations": "1.0.0-rc1-final"
   },
       "commands": {
   	"ef": "Atquin.EntityFramework.Migrations"
   }
  1. If you don't have already, add a DataContextFactory that will create a DataContext using your config.json's connection string;
   public class MyContextFactory : IDbContextFactory<MyDataContext>
   {
       private IConfiguration _config;

       public MyContextFactory()
       {
           _config = new ConfigurationBuilder().AddJsonFile("config.json").Build();
       }

       public MyDataContext Create()
       {
           return new MyDataContext(_config["Data:DefaultConnection:ConnectionString"]);
       }
   }
  1. Add a configuration to Migrate/Seed data;

namespace MyProject.Data.Migrations
{
       internal sealed class Configuration : DbMigrationsConfiguration<MyDataContext>
       {
           public Configuration()
           {
               AutomaticMigrationsEnabled = false;
               MigrationsDirectory = "Migrations"; // should match the end of your Namespace above
           }

           protected override void Seed(MyDataContext context)
           {
               Console.WriteLine("Executing seed...");
               ...
           }
       }
}
  1. Open command prompt and execute the following;
cd /your/datacontext/directory
dnx ef add MigrationName
  1. VS2015 will then immediately generate a same-named *.cs for the *.resx file created. Delete that *.cs file.
  2. Now you can update the database;
dnx ef update

Specifying a custom conection string

See the options below. Example;

dnx ef update -c "Data Source=myServerAddress;
location=myDataBase;User ID=myUsername;password=myPassword;" -p Npgsql

Options

dnx ef add --help

Usage: ef add [arguments] [options]

Arguments:
  [name]  Migration name label

Options:
  -?|-h|--help           Show help information
  -c|--connectionstring  The connection string
  -p|--provider          The provider name
  -i|--ignore            Ignore model changes

dnx ef update --help

Usage: ef update [options]

Options:
  -?|-h|--help           Show help information
  -c|--connectionstring  The connection string
  -p|--provider          The provider name

entityframework-migrations's People

Contributors

staff0rd avatar

Stargazers

Massimiliano Donini avatar

Watchers

James Cloos avatar  avatar  avatar

entityframework-migrations's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.