views:

196

answers:

6

What are some pros and cons of using ASP.NET MVC with Entity Framework in .NET 4.0? Any 'gotchas' in live scenarios?

+3  A: 

What I really like about ASP.NET MVC is:

  • It forces you to use Separation of concerns;
  • Full control of HTML output;
  • It's easier to write unit test;
  • Very extensible;
  • Open Source :D
  • NO VIEWSTATE! That means, faster browsing.

On the other side, I find WebForms more productive for large enterprise applications full of grids, ajax and web controls.

Guilherme Oenning
While your answer is correct "Open Source" and maybe Extensible is the only thing you can't do with WebForms.
jfar
True, you CAN do it with WebForms. But it's harded, WebForms was first develop not thinking about html output or unit testing, now that we are on WF4 we got some new features to there problems. If you want to do TDD on a WF application you need to implement MVP/MVC pattern on your own. ASP.NET MVC gives it out of the box. Anyway, I like both, I just choose the one who best fit my requirements.
Guilherme Oenning
A: 

Bunch of new stuff like AjaxHelpers and AjaxExtensions that set the stage for some interesting things the community could do with ASP.NET MVC and Ajax. I'd like to see some JQuery love in there, maybe with some MVCContrib as they've been quiet lately.

PROS

  1. Found much easier to do with MVC was to have multiple versions of a page that displayed the same data, but in a slightly different format.
  2. MVC makes it simple to unit test the logic that is specific to a page. To do so, you simply test the actions in your controllers, which are regular, easy to test classes.
  3. The best part about using an MVC framework is that everything in the web application has a standard structure and it is compartmentalized.

CONS

  1. If you decide to convert your site to MVC, you may also run into issues trying to maintain existing page addresses.

  2. spending some time writing rules that perform the necessary 301 redirects, because you don’t want to take chances with SEO (Search Engine Optimization).

  3. One of the problems is that MVC frameworks can be incredibly bulky. They require a lot of files for everything to work properly.

Spooks
Your point about bloat is a very valid one
Doozer1979
Bloat? The way I see it, you just need one `.cs` file (controller) and one `.aspx` file (view) to do anything. Similar to WebForms with a `.aspx` and `.cs` (codebehind). I'm not sure where the `bloat` comes in..
Baddie
Well if you're going to do it like that what's the point in using MVC at all?
Doozer1979
Where's the 'M' in MVC in your viewpoint. You can do it the way you're suggesting, but your application will be a mess and a nightmare to unit test. Doing it the MVC way means you trade off a slimline app, for easier maintainability. In the long run i know which one i prefer.
Doozer1979
+1  A: 

I'm learning ASP.NET MVC at the moment on a personal project and am finding it great. I really like:

  • Edit/Display templates
  • Custom extension methods on HtmlHelper for various extras I want
  • Integration with jQuery, making client-side extensions relatively straightforward

I'm also trying out EF4. It seems ok, though I would like better support for versioning database changes. I'm not using the POCO objects either, which means if you display an entity on the UI, you can't use the validation attributes (easily -- you can with a metadata type but it is ugly). I'm tending introduce ViewModel classes between entities and the View anyway, as they allow other types of supplementary data that do not belong in the entity.

Drew Noakes
A: 

With regards to the entity Framework, the early stages of developing apps where the model is frequently changing, is really easy with EF4. You code your models and controllers up first and then the framework can automatically create a basic view, and script up a database for you. This is a real boon to productivity.

Spooks point about bloat is really valid, not sure if this is specific to .NET MVC, but small project can quickly balloon to hundreds of files.

Doozer1979
+1  A: 

ASP.NET MVC is around for sometime. Entity framework 4.0 is just released. There is lot of push for both these technologies from Microsoft evangelists like Scott Guthrie and Scotth Hanselman.

Most of the examples of entity framework are shown using ASP.NET MVC as front end. Entity framework might not be as matured as some of the other ORM technologies like NHibernate. But I believe it is definately the next big thing that MS is pushing for.

Take a look at my blog about getting started with EF code first approach here Here is another link which can be used with existing databse schema and entity framework query databse using entity framework

Nilesh Gule
A: 

I don't see that there could be any problems using the two together, since they deal with two opposite ends of the application, that shouldn't even need to know that the other exists.

If you ASP.Net code is properly factored, it's controllers should not be affected by whether the objects it uses come from EF or some other ORM.

Jonny Cundall