Created
December 22, 2015 20:51
-
-
Save thinktainer/e7a49b09d0cc1e15c434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
All done and working (at least the initial EF migration) with PostgreSQL. | |
For anyone wanting to use it basic steps are: | |
Install PostgreSQL (http://www.postgresql.org/download/linux/) | |
Create a username and pass you would like to use in EF. Via terminal type: | |
sudo -u postgres psql | |
psql#> create user createdb createuser password ‘’; | |
psql#> \q | |
In your project.json add reference to Npgsql | |
"frameworks": { | |
"dnx451": { | |
"dependencies": { | |
"EntityFramework7.Npgsql": "3.1.0-beta7-1" | |
} | |
} | |
In your Startup.cs in ConfigureServices, use Npgsql | |
services.AddEntityFramework() | |
.AddNpgsql() | |
.AddDbContext(); | |
In your context (or in the AddNpgsql() call above) setup the connection string to match the username and password created in step 2. I've done it in the DbContext: | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
// And PostgreSQL for Linux | |
optionsBuilder.UseNpgsql("Server=127.0.0.1;Port=5432;Database=desired_database_name;User Id=username_from_step2; Password = password_from_step2;"); | |
} | |
Back to terminal, go to your project directory, do a dnu restore and dnu build to make sure your project builds ok. | |
From project directory, create your EF initial migration if you havent already. | |
dnx ef migrations add InitialMigration | |
Now get ef to create the database in your PostgreSQL server | |
dnx ef database update | |
Install DbVis or SquirrelSQL to connect to your database and visuall confirm all is well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment