Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Using EFCore with Postgres SQL Data Provider

$
0
0

Hello friends,

I'm trying to EF Core 1.0 with PostgreSQL data provider. I'm trying first with C# Console App for learning, here is my context class:

public class unapeDbContext : DbContext
{
    public unapeDbContext(DbContextOptions<unapeDbContext> options) : base(options) { }
    public DbSet<Item> Items { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("User ID=postgres;Password=;Server=postgres;Port=5432;Database=unapeDbContext;Pooling=true;");
    }
}


I added the following packages:

"dependencies": {"Microsoft.NETCore.App": {"type": "platform","version": "1.0.0"
},"Microsoft.EntityFrameworkCore": "1.0.0","Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0","Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final"
},

Now when I try to add a migration as "

dotnet ef migrations add InitialMigrations"
 I get the following error in the console:

No parameterless constructor was found on 'unapeDbContext'. Either add a parameterless constructor to 'unapeDbContext' or add an implementation of 'IDbContextFactory<unapeDbContext>' in the same assembly as 'unapeDbContext'.

When I added a parameterless constructor in the context class, I still don't see any data in my database.

Please also provide a link of 1-1 for using PostgreSQL with EFCore if you have any.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>