MvcScaffolding - 它支持模型优先吗?
我已经尝试过 MvcScaffolding 项目 - 非常好顺便说一句;但是,有谁知道它是否支持模型优先设计方案(例如 EF4 数据模型 -> 从数据库生成)?
如果它确实支持模型优先场景,您是否知道任何描述模型优先设计场景的链接?
谢谢...
I've toyed around with the MvcScaffolding project - very nice BTW; however, does anyone know if it supports Model First design scenarios (e.g. EF4 Data Model -> Generate from Database)?
If it does in-fact support Model First scenarios, do you know of any links describing a Model First design scenario?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
MvcScaffolding 就其脚手架适用的场景而言非常灵活。但是,要支持除默认代码优先之外的任何内容,您可能需要稍微调整输出。 MvcScaffolding 本身没有任何约束,而是您首先使用模型,代码优先或其他。你所要做的就是将它指向一个公共类,它就会搭建它的脚手架。
但是,MvcScaffolding 附带的文本模板旨在生成与 EF 4.1 代码优先类型交互的控制器代码,因此需要对生成的控制器代码进行一些调整以支持模型优先场景。
我刚刚使用模型优先方法完成了整个 MvcScaffolding 实现。就我而言,我不想使用仍处于预发布状态的实体框架 4.1。此外,我不想手动编写实体模型所需的所有类型。我没有在生成完成后调整输出,而是编辑了模板以完全按照我想要的方式生成代码。最终结果是我能够针对模型优先实体框架 4.0 实现生成、编译和运行。
如果您不害怕稍微调整一下,MvcScaffolding 并不挑剔它将为哪些场景构建脚手架代码。使用实体框架 4.1 中实现的代码优先场景肯定更容易,但只需做一些工作,您就可以让它支持模型优先场景。
MvcScaffolding is pretty flexible in terms of what scenarios it's scaffolding will work for. However to support anything other than the default which is code first you may have to tweak the output a little. MvcScaffolding itself doesn't have any constraints around rather you're using model first, code first or whatever. All you have to do is point it to a public class and it will scaffold it.
However, the text templates that ship with MvcScaffolding are designed to generate controller code that interfaces with EF 4.1 code first types, so there would be some tweaking of the generated controller code necessary to support a model first scenario.
I just completed an entire MvcScaffolding implementation using a model first approach. In my case I didn't want to use entity framework 4.1 which is still pre-release. Additionally, I didn't want to hand code all of the types required by my entity model. Rather than tweak the output after the generation was complete, I edited the templates to generate the code exactly the way I wanted it. The end result was I was able to generate, compile and run against a model first entity framework 4.0 implementation.
MvcScaffolding isn't picky about what scenarios it will scaffold code for if you're not afraid to tweak it a little. It is definitely easier to work with code first scenarios as implemented in entity framework 4.1 but with a little work you can get it to support model first scenarios as well.
我目前也在探索这个问题。 的示例
这是使用 Northwind http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx
看起来也像那里是一个陷阱
http://mvcscaffolding.codeplex.com/discussions/247163
我的一些笔记和屏幕截图在这里:
http://www.programgood.net/2011/03/11/ EntityFramework.aspx
I'm exploring this too currently. Here is an example using Northwind
http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx
Also looks like there is a gotcha
http://mvcscaffolding.codeplex.com/discussions/247163
Some of my notes and screenshots here:
http://www.programgood.net/2011/03/11/EntityFramework.aspx
请访问 http://www.devart.com/linqconnect/ 查看 LinqConnect。我还没有使用过它,但过去一周我一直在研究它,我认为它听起来很令人兴奋。
Check out LinqConnect at http://www.devart.com/linqconnect/. I haven't used it yet, but I've been researching it over the past week and I think it sounds exciting.
使用 Model First 和 Entity Framework 4.1 构建 MVC 3 应用
Julie Lerman 向我们展示了如何在 MSDN 上手动完成
我的建议:在 Models 文件夹下生成强类型实体类并创建真实数据库后,使用 mvcscaffolding:
PM>scaffold Controller MyEntityClass
Building an MVC 3 App with Model First and Entity Framework 4.1
Julie Lerman show us how to do it by hand on MSDN
My suggestion: after strongly typed entity classes have been generated under Models folder and real database has been created, use mvcscaffolding:
PM>scaffold Controller MyEntityClass
是的,确实如此。而且也很好。
即我成功地将它与新的 DbContext POCO T4 模板一起使用
例如
这将删除:ObjectContext 派生的 .designer.cs 代码,并替换为 DbContext .tt 文件。
然后脚手架走开! (记住将 -DbContextType 传递到您的脚手架命令中)
Yes it does. And very well too.
i.e. I am using it successfully with the new DbContext POCO T4 templates
e.g.
This will remove the : ObjectContext derived .designer.cs code, and replace with the DbContext .tt files.
Then scaffold away ! (remembering to pass the -DbContextType into your scaffolding cmds)
我已经提出了针对数据库第一个场景执行此操作的步骤。请参阅 http: //weblogs.asp.net/paullitwin/archive/2011/08/11/use-mvc-scaffolding-in-database-first-mode.aspx
I have come up with the steps to do this for a database first scenario. See http://weblogs.asp.net/paullitwin/archive/2011/08/11/use-mvc-scaffolding-in-database-first-mode.aspx