.NET实体框架核心 [英] .NET Entity Framework Core

查看:123
本文介绍了.NET实体框架核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去两年中,我已经阅读了几乎所有其他有关EF的问题。我下载其他软件包没有问题,只是不会为我安装的Entity Framework。

I've already read through pretty much every other issue regarding EF in that was posted in the past 2 years. I have had no problems downloading other packages, it's only Entity Framework that will not install for me.

我什至尝试安装最新版本的Nuget并使用它的工具在我的项目目录内部以还原软件包-之后-我在.csproj中添加了以下行:

I've even tried installing the latest version of Nuget and using it's tool inside of my project directory to restore the packages -after- I added a this line to my .csproj:

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />

首先,我尝试了以下命令:

First I tried this command:

dotnet restore

输出以下内容:

C:\Path\To\My\Project>dotnet restore
Restore completed in 100.41 ms for C:\Path\To\My\Project\TestNuget.csproj.
Restore completed in 68.84 ms for C:\Path\To\My\Project\TestNuget.csproj.

,结果为:

> dotnet ef
No executable found matching command "dotnet-ef"

匹配的可执行文件,所以我尝试了(使用截至今天的最新版本的Nuget):

So then I tried this (using the latest version of Nuget as of today's date):

nuget restore Example.csproj

输出以下内容:

MSBuild auto-detection: using msbuild version '15.6.85.37198' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'.
Committing restore...
Tool assets file has not changed. Skipping assets file write. Path: C:\Path\ToNuget\.nuget\packages\.tools\microsoft.visualstudio.web.codegeneration.tools\2.0.3\netcoreapp2.0\project.assets.json
Restore completed in 139.95 ms for C:\Path\To\User\source\repos\Example\Example\Example.csproj.
Committing restore...
Assets file has not changed. Skipping assets file writing. Path: C:\Path\To\User\source\repos\Example\Example\obj\project.assets.json
Restore completed in 113.51 ms for C:\Path\To\User\source\repos\Example\Example\Example.csproj.

NuGet Config files used:
    C:\Path\To\User\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.Fallback.config

Feeds used:
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    https://api.nuget.org/v3/index.json

结果相同。

我根本不确定问题是什么,我在网上阅读的所有内容,包括 https://docs.microsoft.com/zh-cn/ef/core/miscellaneous/cli/dotnet
表示您要做的只是更改.csproj文件并使用dotnet / nuget程序包管理工具进行还原,但这似乎对我的项目毫无作用,并且dotnet-ef.exe仍然找不到。

I'm not at all sure what the problem is, everything I'm reading online, including https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet is stating that all you have to do is a alter the .csproj file and restore using the dotnet/nuget package managing tool, but this seems to do absolutely nothing to my project, and dotnet-ef.exe is still no where to be found.

推荐答案

我做了以下工作,并且有效

I did the following and it works,


  1. 创建一个新的.NET核心MVC Web应用程序

  2. 转到命令提示符,将
    目录更改为您的应用程序项目文件夹

  3. 执行以下命令
  4. >
  1. Create a new .NET Core MVC Web App
  2. Go to command prompt, change the dir to your application project folder
  3. Execute the following command




dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet restore


执行上述命令后,
包括.csproj文件中的行下面(紧接在结束的Project标记之前)

After the above commands are executed, Include the below lines in your .csproj file (just before the closing Project tag)

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>

完整的.csproj文件可能如下所示,

The complete .csproj file may look like as below,

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
  </ItemGroup>
  <ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>

</Project>

键入 dotnet ef

如果所有配置都正确,您将看到以下响应

If all the configurations are fine, you will see the following response

                     _/\__
               ---==/    \\
         ___  ___   |.    \|\
        | __|| __|  |  )   \\\
        | _| | _|   \_/ |  //|\\
        |___||_|       /   \\\/\\

Entity Framework Core .NET Command Line Tools 2.0.0-rtm-26452

Usage: dotnet ef [options] [command]

Options:
  --version        Show version information
  -h|--help        Show help information
  -v|--verbose     Show verbose output.
  --no-color       Don't colorize output.
  --prefix-output  Prefix output with level.

Commands:
  database    Commands to manage the database.
  dbcontext   Commands to manage DbContext types.
  migrations  Commands to manage migrations.

Use "dotnet ef [command] --help" for more information about a command.

这篇关于.NET实体框架核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆