MVC 3 Sample w LLBLGen

Posts   
 
    
Posts: 94
Joined: 23-Aug-2006
# Posted on: 24-Apr-2011 15:37:45   

Looking for an MVC sample app using LLBLgen.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Apr-2011 22:12:06   

There is no examples for MVC. If you had used LLBLGen and you had used MVC, there is no much to tell: fetch the entities in your controller and pass them to the view. I have a couple of examples. I will post one here later today.

David Elizondo | LLBLGen Support Team
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Apr-2011 07:58:00   

I've an MVC2 example. Let me give you it in MVC3. Please give me a couple of hours...

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 27-Apr-2011 01:57:09   

David thats very nice of you. Do you happen to have a way to map entities to models and extend them with DataAnnotations?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Apr-2011 13:33:58   

Hi there,

I had an example for MVC2 but it not uses an example database (it uses one of mine), so I write down a tiny MVC3 example using Northwind. You can learn the basics from it.

It's not much different from MVC2 really. I use the default ASP.Net view engine (not Razor), no html5, just the basic stuff. You can add those if you want.

Also, in MVC there is not much different from LLBLGen and other frameworks. The default binder works very well with LLBLGen entities.

When you pass an entity from a view to the controller, the mvc binder pass the fields as form parameter collection. A nice addition is to tell MVC to pass an entity back and forth between the controller and the view, instead of parameters. To do that I used the Brian Chance's LLBLGenModelBinder class (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17343).

The DataAnnotations is very easy to add. You can do it in a partial class in you entity model project or via buddy classes. I added a few validation decorators to show this.

All you need to run this example is: Northwind db, VS2010, MVC3, LLBLGen v3.1.

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 27-Apr-2011 14:25:49   

That sounds great. Where do I find the file?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Apr-2011 14:33:18   

There is a tiny clip in my above post. Or click here: http://www.llblgen.com/TinyForum/Attachments.aspx?SourceType=1&MessageID=111280

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 27-Apr-2011 14:37:53   

Got it ! Thanks. Appreciate it

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 27-Apr-2011 14:45:24   

Great work David simple_smile

Also to add attributes to entities, navigators etc., you can do that in the designer (at the project level for example to define it once and add the attributes to all entities, fields etc.)

Frans Bouma | Lead developer LLBLGen Pro
scotru
User
Posts: 104
Joined: 16-Feb-2006
# Posted on: 22-May-2011 10:14:29   

Thanks for sharing this David! Is it possible to use this with MVC Scaffolding?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2011 22:26:58   

What version of MVC are you using? Do you use some special custom scaffolding package or the default one?

David Elizondo | LLBLGen Support Team
scotru
User
Posts: 104
Joined: 16-Feb-2006
# Posted on: 23-May-2011 08:07:54   

I'm using MVC 3. I'm just trying to get basic scaffolding working. I've tried using the UI to create the controller with scaffolding in Web Developer 2010 as well as using the package manager as described here:

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

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-May-2011 06:47:34   

I never looked at MCV scaffolding and LLBLGen, the closest thing is the DynamicData support released time ago. Let me take a look at scaffolding to see if it's possible. I will post the results tomorrow.

David Elizondo | LLBLGen Support Team
scotru
User
Posts: 104
Joined: 16-Feb-2006
# Posted on: 25-May-2011 00:03:17   

Awesome--I appreciate that. Scaffolding is the only thing making me tempted to use EF4 instead of LLBLGen right now with MVC 3. I'm tired of spending too much time writing CRUD :-)

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-May-2011 07:41:31   

The default and only option is EF for scaffolding. Nevertheles you can override the templates to write your own code: http://blog.stevensanderson.com/2011/04/06/mvcscaffolding-overriding-the-t4-templates/ http://stackoverflow.com/questions/4692311/how-do-i-create-my-own-scaffold-template-in-asp-net-mvc-3

As this are very straight-forward templates, you also could write your own LLBLGen templates to generate that. It should be relatively easy to do, if you want to give it a spin.

David Elizondo | LLBLGen Support Team