开发者

MvcScaffolding - Does it support Model-First?

I've toyed around with the MvcScaffoldin开发者_运维问答g 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...


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.


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


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.


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


Yes it does. And very well too.

i.e. I am using it successfully with the new DbContext POCO T4 templates e.g.

  1. Add your edmx => update from database
  2. Right click the edmx designer
  3. Select "add code generation item"
  4. Select ADO.NET DbContext Generator

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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜