如何将EF核心搭建到现有数据库?

时间:2016-02-09 20:08:27

标签: ef-code-first asp.net-core entity-framework-core

我正在尝试使用Entity Framework Core对现有数据库进行逆向工程。我尝试按照from Microsoft的说明操作,但我收到了错误消息:

  

无法找到名为EntityFramework的提供程序程序集。确保指定的名称正确并且由项目引用。

我正在从项目目录运行以下命令:

dnx ef dbcontext scaffold "Server=REMOVED;Database=REMOVED;User ID=REMOVED;Password=REMOVED" EntityFramework

我做错了什么?

4 个答案:

答案 0 :(得分:1)

确保您位于项目文件夹而不是解决方案文件夹上下文中。我昨天能够使用以下内容(最后注意EntityFramework.MicrosoftSqlServer)

dnx ef dbcontext scaffold "{connectionString}" EntityFramework.MicrosoftSqlServer

编辑:

确保在project.json中包含以下内容:

EntityFramework.MicrosoftSqlServer.Design

答案 1 :(得分:1)

安装休闲的NuGet软件包:

public Form1()
{
    InitializeComponent();

    this.DoubleBuffered = true;
    this.SetStyle(ControlStyles.ResizeRedraw, true);
}

protected override void OnPaint(PaintEventArgs e)
{
    e.Graphics.FillRectangle(Brushes.Transparent, Top());
    e.Graphics.FillRectangle(Brushes.Transparent, Left());
    e.Graphics.FillRectangle(Brushes.Transparent, Right());
    e.Graphics.FillRectangle(Brushes.Transparent, Bottom());
}

private const int HTLEFT = 10;
private const int HTRIGHT = 11;
private const int HTTOP = 12;
private const int HTTOPLEFT = 13;
private const int HTTOPRIGHT = 14;
private const int HTBOTTOM = 15;
private const int HTBOTTOMLEFT = 16;
private const int HTBOTTOMRIGHT = 17;

protected override void WndProc(ref System.Windows.Forms.Message m)
{
    base.WndProc(ref m);
    if (m.Msg == 0x84)
    {
        var mp = this.PointToClient(Cursor.Position);

        if (TopLeft().Contains(mp))
            m.Result = (IntPtr)HTTOPLEFT;
        else if (TopRight().Contains(mp))
            m.Result = (IntPtr)HTTOPRIGHT;
        else if (BottomLeft().Contains(mp))
            m.Result = (IntPtr)HTBOTTOMLEFT;
        else if (BottomRight().Contains(mp))
            m.Result = (IntPtr)HTBOTTOMRIGHT;
        else if (Top().Contains(mp))
            m.Result = (IntPtr)HTTOP;
        else if (Left().Contains(mp))
            m.Result = (IntPtr)HTLEFT;
        else if (Right().Contains(mp))
            m.Result = (IntPtr)HTRIGHT;
        else if (Bottom().Contains(mp))
            m.Result = (IntPtr)HTBOTTOM;
    }
}

private Random rng = new Random();
public Color randomColour()
{
    return Color.FromArgb(255, rng.Next(255), rng.Next(255), rng.Next(255));
}

const int ImaginaryBorderSize = 2;

public new Rectangle Top()
{
    return new Rectangle(0, 0, this.ClientSize.Width, ImaginaryBorderSize);
}

public new Rectangle Left()
{
    return new Rectangle(0, 0, ImaginaryBorderSize, this.ClientSize.Height);
}

public new Rectangle Bottom()
{
    return new Rectangle(0, this.ClientSize.Height - ImaginaryBorderSize, this.ClientSize.Width, ImaginaryBorderSize);
}

public new Rectangle Right()
{
    return new Rectangle(this.ClientSize.Width - ImaginaryBorderSize, 0, ImaginaryBorderSize, this.ClientSize.Height);
}

public Rectangle TopLeft()
{
    return new Rectangle(0, 0, ImaginaryBorderSize, ImaginaryBorderSize);
}

public Rectangle TopRight()
{
    return new Rectangle(this.ClientSize.Width - ImaginaryBorderSize, 0, ImaginaryBorderSize, ImaginaryBorderSize);
}

public Rectangle BottomLeft()
{
    return new Rectangle(0, this.ClientSize.Height - ImaginaryBorderSize, ImaginaryBorderSize, ImaginaryBorderSize);
}

public Rectangle BottomRight()
{
    return new Rectangle(this.ClientSize.Width - ImaginaryBorderSize, this.ClientSize.Height - ImaginaryBorderSize, ImaginaryBorderSize, ImaginaryBorderSize);
}

答案 2 :(得分:1)

尝试从现有的SQLite数据库中进行脚手架安装时出现以下错误:

Unable to find provider assembly with name Microsoft.EntityFramworkCore.Sqlite. Ensure the specified name is correct and is referenced by the project.

该项目与另一个项目处于解决方案中。即使在Package Manager控制台中引用了正确的项目,它也只有在我在项目上下文菜单中选择“设置为启动项目”项时才起作用。

答案 3 :(得分:1)

关闭Visual Studio
删除%temp%文件夹
删除.vs文件夹

dotnet ef dbcontext scaffold "Server=REMOVED;Database=REMOVED;User ID=REMOVED;Password=REMOVED" Microsoft.EntityFrameworkCore.SqlServer