实体框架7的DbContext支架 [英] Entity Framework 7 DbContext scaffold

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

问题描述

我想生成一个的DbContext 使用ASP.NET 5和Entity Framework 7不足为奇现有的数据库结构,没有周围的很多文档如何做到这一点很容易。此外,我想只有脚手架的背景下;有〜900表,我只关心他们几个,我不需要模型类的每一个。

我一直在使用指定的命令<一href=\"http://stackoverflow.com/questions/32377834/database-first-ef7-beta7-dnx-ef-dbcontext-scaffold-command-fails\">here和<一个href=\"http://stackoverflow.com/questions/29300777/is-there-an-entity-framework-7-database-first-poco-generator\">here有一点运气。

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


  1. 其中位于生成上下文文件?我跑在没有故障的命令提示符下命令,但没有什么事情发生。我知道我至少在正确的地方,我可以添加具有不受支持的属性,老EF6模型,它给了我,他们不支持的错误。


  2. 是否有可能产生只是一个没有相应的模型类方面?



解决方案

我和我的项目产生的背景和模特同样的问题。下面是我做了几件事情。

更新1.0 RC1低于

Project.json

 依赖:{
    EntityFramework.MicrosoftSqlServer:7.0.0-RC1决赛
    EntityFramework.Commands:7.0.0-RC1决赛
    EntityFramework.MicrosoftSqlServer.Design:7.0.0-RC1决赛
  },  命令:{
    EF:EntityFramework.Commands
  },  构架: {
    dnx451:{},
    dnxcore50:{}
  }

DNX命令

  DNX EF的DbContext脚手架的ConnectionStringEntityFramework.MicrosoftSqlServer

原文发表在

请确保这些被添加到您的project.json文件:

 依赖:{
    EntityFramework.SqlServer:7.0.0-联蛋白β7,
    EntityFramework.Commands:7.0.0-联蛋白β7,
    EntityFramework.SqlServer.Design:7.0.0-联蛋白β7
},
命令:{
    EF:EntityFramework.Commands
}

dnvm和DNX运行时以及使用的 dnvm更新自的和的 dnvm升级

升级。我在cmd中运行这个。

打开cmd.exe,在项目位置(如果你是在Windows中,导航到文件夹和Shift +文件夹中单击右键,然后单击打开命令窗口在这里)。在我来说,我有一个单独的项目对我的数据访问层
例如。

  C:\\项目\\实例#1 \\ SRC \\ StackoverflowExample.DAL \\

然后我通过Simplay跑:


  

DNX EF的DbContext脚手架数据源=;初始
  目录=数据库;集成安全性=真EntityFramework.SqlServer


请确保您的项目可以建立。如果有错误,可能是命令不会工作。

有产生所有的模型以及上下文(每个实体的OnModelCreating()设置)。如果你并不需要所有的模型,只是删除不使用的人。

因此​​,要回答你的问题:


  1. 它创造,你在运行DNX EF的DbContext支架文件夹中的模式和内容。

  2. 我不能看,可以让你做到这一点还没有任何命令。
    运行的 DNX EF --help 的在cmd中,寻找自己。
    DNX EF

我希望这有助于。

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.

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

So, I guess I have two questions:

  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.

  2. 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.

Updates For 1.0 RC1 below

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 Command

dnx ef dbcontext scaffold "connectionString" EntityFramework.MicrosoftSqlServer

Original Post Below

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"
}

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

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\

I then simplay ran:

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.

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.

So to answer you questions:

  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

I hope this helps.

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

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