Best way to get closer to binding in Entity Framework 4 ("Database first") and MVC3

I am a relative newbie to C # .Net (.net 4), EF4, Winforms and MVC3.

I created a database in SQL Server during the development of the Winforms backend for the task that I assigned. I set up one solution and create .edmx from the database as my own project / assembly in the solution. The solution also has a winforms application that references the .edmx assembly. Using the default EF4 code generation, I created a Winforms application, and everything is fine there.

Now I need to create an enduser frontend. I want to use MVC3. I went through the MVC3 tutorials on Pluralsight and a pretty decent understanding of MVC3 from that. But, both in this and elsewhere, most MVC3 + EF4 examples are the "first code."

My confusion is the best approach to integrate the EF4 database - first with MVC3? I looked at some on EF4Templates, but it seems they generate POCOs that are different from EF4 by default and will crash my Winforms application. I read some about repositories and using Automapper. I can add a reference to EF4 and my .edmx to the MVC3 project (same as with Winforms), but it seems that I still need to construct a controller / view model. Or can you just work directly with the EF4 classes by default controller?

Just find some recommendations on how to approach this with respect to MVC3.

Thanks!

+4
source share
1 answer

If you want, you could work directly with the standard EF4 classes in the controller. Tool support in the MVC 3 Tools Update for adding and building forest controllers works with the code first, but you can also use the existing context from .edmx if you want to work directly with objects.

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

If you prefer to use the repository template in your application, you can check out the MvcScaffolding package, some information on this can be found in Steve Sanderson's blog.

http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

You can also create presentation models yourself if you want to follow this route.

+1
source

All Articles