views:

65

answers:

2

I'm pretty sure I am a bit confused here (I'm even confused about being confused).

I've already created my database in SQL Server 2008.

I'm now trying out S#arp Architecture for the first time and I'm was looking into using CRUD scaffolding. From the instructions it seems like I basically have to RECREATE the entire database within the ScaffoldingGeneratorCommand.tt file? Kinda pointless for me, right?

Am I trying to go backwards here? What I'd like to do is go from my existing database to CRUD classes.

+1  A: 

If you are doing Brownfield development (which you are), then you can go one of two ways:

  1. Create the Entities / Controllers / Views manually
  2. Use the Scaffolding generator to create the above for you

Depending on how complex your existing database might be, you would be able to choose one over the other. If your existing database's schema is complex, has field names that are not what you would want in your entity you may want to go with option 1 as well as using ClassMaps instead of the automapping from Fluent NHibernate.

Also, depending on how many tables you have as well as how large they are (number of fields), using the Scaffolding Generator might still not be a bad option. To give you an idea, I've used to in a brownfield situation several times with rather large medical databases. It went much faster than me recreating those manually.

In the end, you really need to decide which way would be faster for you as well as which one would be more relevant. We have a pretty strong community with S# so getting some support is not an issue.

Alec Whittington
+3  A: 

If all you've done is created the database, you may want to consider scrapping that and creating the classes first as in option 1 from Alec. Then you can let NHibernate generate the database for you.

But to answer your question, I've always just created the models/views/controllers from scratch since I never really liked the output of generated code. I believe SharpArch is even planning on doing away with the T4 templates in favor of Templify [source] because of it's issues.

Chris Conway
Hm, yah, I never like generated code either. I'm beginning to think MVC is for crazy folks who enjoy taking everything they've learned and throwing it out. Seriously. Masterpages were amazing until MVC came along and...now I need 70 kabillion extra files just to change the title of the page. ugh. </rant>
David Murdoch
Don't blame MVC for legacy WebForms engine limitations. For example, Spark view engine eliminates setting title and many other "issues" that you have "with MVC".
queen3
yeah, i wouldn't say it's throwing out everything you know. it's more like re-learn everything you should know anyways.
Chris Conway
You are going through the same phase everyone else has already gone through. Luckily for some of us, we started with HTML / JS so going back to it is not as big of a change as it is for others. If you stick with it, you will start to get it and like it. Just be thankful you are getting into it now and not Dec 07 when it was totally "figure it out yourself".
Alec Whittington
I agree with Alec on this one. If you're familiar with HTML and JS, you're over half way there. While you don't get to drag and drop a DropDownList onto a page, you do have a lot more control over how that select list is used, especially if you need to do javascript on it. No more need to know what that ASP.Net rendered ClientId is! ctl$0_MyDropdown <- yuck!
Chris Conway
Well, I've actually scrapped the MVC idea for now; the S# templates ended up being more confusing than VS's MVC 2 templates. I'll probably have a go at it again on the next project.The HTML / JS parallel is something I hadn't thought about...still not quite a 1:1 comparison though. Thanks for the suggestions, tips, and encouragement!
David Murdoch
Oh, and to "solve" the database code generation issue I've settled on using LINQ to SQL.
David Murdoch