ErikEJ / EntityFramework6PowerTools

This is the codebase for Entity Framework 6 Power Tools Community Edition, and modern EF 6 providers for SQL Server and SQL Server Compact
Other
183 stars 27 forks source link

Cannot find DbContext in file #16

Closed shawty closed 6 years ago

shawty commented 6 years ago

Hi Erik, Just been trying this in VS2017 with a DotNet core app (Created using the new SPA templates by Steve Sanderson)

Everything works ok, and builds, but right clicking on my Data context file, and going "Entity Framework -> View Entity data model"

Always results in the project being built, and then failing at the end with: "A construct-able type deriving from DbContext could not be found in the file"

Further research suggests that it's because there was no parameter-less constructor in the DbContext, so I added a parameter-less ctor, with a static configuration, and still no dice.

My DbContext is as follows (Edited to remove sensitive info):

` using MYPROJECT.Database.Models; using Microsoft.EntityFrameworkCore;

namespace MYPROJECT.Database
{
  public class DataContext : DbContext
  {
    public DataContext(DbContextOptions<DataContext> options) : base(options)
    {}

    public DataContext() : base(new DbContextOptions{ "MY OPTIONS HERE" })
    {}

    public DbSet<TableOneType> TableOne { get; set; }
    public DbSet<TableTwoType> TableTwo { get; set; }
  }
}

`

Further to this, for some reason, after I try to run it and it fails, it also does something to upset the loaded EF config, and once Iv'e tried and failed, any operation I then try to do using EF, even something simple like saving the DbContext class in the IDE, I get a modal popup with the following in

image

The only way I can get VS back to a state where I can use it without this popup appearing is to just dump the entire VS instance, and reload everything from scratch.

Environment: VS2017 Enterprise, running on Win7 x64, with all current updates and patches. Dotnet Standard upto 4.6.1 is available Dotnet Core upto 2.0.0 is available

Project is configured for Dotnet Core 1.0.4 (Final Target is Ubuntu Linux), and is using ASP.NET Core w/MVC and EF Core 6

EF is using NpgSql as target DB is a postgres 9.5 instance. EF config and build is inject via DI in the Startup.cs class

Cheers Shawty

ErikEJ commented 6 years ago

This is the EF 6 Power Tools and you use EF Core! You can try my EF Core Power Tools instead.

shawty commented 6 years ago

Ah ok, I was not aware there was a separate one for core :-)

Can you give me the link to the VS Market place page for it please, and I will try.

If this is a case of mistaken Identity and the core version works, then I'll open a new issue, please close this one.

ErikEJ commented 6 years ago

https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools - but just go to Tools, Extensions and Updates in VS, and search online there!

shawty commented 6 years ago

Thanks :-)