实体框架7 DbContext脚手架 [英] Entity Framework 7 DbContext scaffold

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

问题描述

我正在使用ASP.NET 5和Entity Framework 7为现有的数据库结构生成一个 DbContext 。毫不奇怪,没有很多文档围绕如何轻松地做到这一点。另外,我只想支架上下文;有〜900表,我只关心其中的几个,我不需要每个模型类。

I am trying to generate a DbContext for an existing database structure using ASP.NET 5 and Entity Framework 7. Not surprisingly, there isn't a lot of documentation surrounding how to do this easily. Additionally, I want to scaffold ONLY the context; there are ~900 tables and I only care about a few of them, I don't need a model class for each one.

我一直在使用指定的命令此处 here ,一点运气。

I've been using the commands specified here and here with little luck.

所以,我想我有两个问题:

So, I guess I have two questions:


  1. 生成的上下文文件位于哪里?我在命令提示符下运行命令,没有失败,但没有其他的事情发生。我知道我至少在正确的地方,因为我可以添加旧的EF6模型与不支持的属性,它给我一个错误,不支持。

  1. Where are the generated context files located? I run the command in the command prompt with no failure, but nothing else happens. I know I'm at least in the right place as I can add the old EF6 model with unsupported properties and it gives me an error that they are not supported.

是否可以生成没有对应模型类的上下文?

Is it possible to generate just a context with no corresponding model classes?


推荐答案

我的项目生成上下文和模型,我也有同样的问题。这是我做的一些事情。

I had the same problem with my project generating the context and the models. Here's a few things that I did.

更新1.0 RC1以下

Project.json

Project.json

  "dependencies": {
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final"
  },

  "commands": {
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  }

DNX命令

dnx ef dbcontext scaffold "connectionString" EntityFramework.MicrosoftSqlServer

原始帖子

确保将这些添加到您的project.json文件中:

Make sure these are added to your project.json file:

"dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "EntityFramework.Commands": "7.0.0-beta7",
    "EntityFramework.SqlServer.Design": "7.0.0-beta7"
},
"commands": {
    "ef": "EntityFramework.Commands"
}

使用 dnvm update-self dnvm升级升级dnvm和dnx运行时。我在cmd中运行了这个。

Upgrade dnvm and the dnx runtimes as well using dnvm update-self and dnvm upgrade. I ran this in cmd.

在项目位置打开cmd.exe(如果您在Windows中,导航到文件夹,并在文件夹中移动+右键单击,点击在这里打开命令窗口)。在我的情况下,我有一个单独的项目为我的数据访问层
例如。

Opened cmd.exe in the project location (if you are in windows, navigate to the folder and shift + right-click in the folder and click "Open command window here"). In my case I had a separate project for my Data Access Layer eg.

C:\Projects\Stackoverflow Example\src\StackoverflowExample.DAL\

然后simplay运行:

I then simplay ran:


dnx ef dbcontext scaffoldData Source =; initial
Catalog = database; Integrated Security = TrueEntityFramework.SqlServer

dnx ef dbcontext scaffold "Data Source=.;Initial Catalog=database;Integrated Security=True" EntityFramework.SqlServer

确保您的项目可以构建。 如果有错误,命令可能无法正常工作。

Make sure your project can build. If there are errors, the commands probably wont work.

它生成所有模型以及上下文(每个实体的OnModelCreating()设置)。如果您不需要所有型号,只需删除不使用的模型。

It generated all the models as well as the context (with the OnModelCreating() setup of each entity). If you don't need all the models, just delete the ones you are not using.

所以要回答你的问题:


  1. 它在您运行dnx ef dbcontext scaffold的文件夹中创建模型和上下文。

  2. 我看不到任何允许您的命令要做到这一点
    在cmd中运行 dnx ef --help ,并寻找自己。
    dnx ef

  1. It creates the models and context in the folder where you ran the dnx ef dbcontext scaffold in.
  2. I cant see any commands that allows you to do this yet. Run dnx ef --help in cmd and look for yourself. dnx ef

我希望这有帮助。

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

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