In this article, Brian Boyce shows how a freeware product called Codesmith can be used to kick-start your projects by demonstrating the development of a set of templates to generate Select, Insert, Update, and Delete stored procedure code together with a corresponding C# data access layer to call the stored procedures.
Then they turn around and tell us that macros are evil
… one can use Microsoft Data Access Application Block (DAAB)to speed some parts even more.
“or you could use a language with *real* OR mappers! ”
there are plenty of OR mappers available for many languages including .NET.
Having an OR mapper might save you some database programming, but you still need to write code every now and then
“one can use Microsoft Data Access Application Block ”
This will also help you with your data access. You will still need to write code (Be it with a DAAB object instead of ADO.NET stuff)
The author used data access as an example, using codesmith templates nothing is stopping you from generating other code which can’t be replaced by a data access component.
“This will also help you with your data access. You will still need to write code (Be it with a DAAB object instead of ADO.NET stuff)”
Not really. The only code you’ll need to write are the helper’s method call you will invoke. Beside that, the block take care of itself pretty well. We reduced our data access layer code by almost %40 since we started using this application block.
For an example of .NET O/R mapping for that requires you to write very little custom code and is generally readable and easy to use, visit my project homepage at:
http://sooda.sourceforge.net/
The code generation part is based on CodeDOM which makes it (theoretically) capable of emitting source code in many languages.
The web page is very basic yet (just some code examples)
but the code is quite stable. It’s available from the Subversion repository. I’m planning the initial public release very soon (will be BSD-licensed).
” very little custom code”
that’s only talking database-wise. And I bet the little code you still need is pretty repetitive
the point of codesmith is not generating dataaccess code, but allowing you to define a template for code instead of writing the same code over and over again.
Don’t be focused on data because that’s what the author chose as an example. It could just as well be something completely different.
“We reduced our data access layer code by almost %40 since we started using this application block. ”
my point is not that data access tools are not useful. My point is that codesmith is more than a dataclass generator.
codesmith is there to allow you to define a template for code you have to write often:
“The only code you’ll need to write are the helper’s method call you will invoke. ”
how many times did you write that line of code by now? still not getting tired of it?
(maybe this is a bad example because it’s only 1 line)
I’m sure all of you can picture something they have written over and over again which could be generated by a templated code generator
Why do people think code generation and O/R mapping are two diametrically opposing forces that must battle it out to the death? I personally use Codesmith to generate custom business classes that can then be used by an O/R Mapper.
Anyways, here’s a listing of some persistence/OR Mappers for .NET:
http://sharptoolbox.madgeek.com/Pages/Category74089b0a-1105-4389-b1…
MySQL .NET Connector
http://lists.mysql.com/announce/212
and it’s free. there is a studio type application for writing codesmith templates but I’m not sure how useful it is over vs .net – which is to mean I don’t understand it’s position as a tool.
Off topic, I know, but nobody has mentioned my favorite OR Mapper and it’s making me crazy
NHibernate
http://nhibernate.sourceforge.net/
nail hammer head….
that’s what i was trying to explain to these people
Tons of developers have been writing data access code generators ever since ADO gave us the ability to inspect a datbases’ structure programatically. My point is that code generators like this ,while “neat”, are an old idea that has not proven particularly useful. My personal experience is that they are only good if you’re writing an application which does generic access on a lot of tables (Select (one field, or all fields) / Insert / Update (all fields at once) / Delete). Once you get in to having to handle foreign key relationships (ex. cascaded deletes) the tools loose much or their usefulness.
it’s not necessarily about databases!!!!!!
arrrrrrrghhhhhhhhh
Other than data access code I don’t tend to have repetitive code to write. Maybe that’s because we actually make use of Object Oriented code! You know? Abstract classes, interfaces, etc? If you are writing the exact same code over and over you need to use OO or refactor you stuff to use smarter functions.
fair enough comment, maybe i got agitated and underestimated you
i know about oo, but that shows that you might me thinking in academic terms and/or bigger projects.
This not only works in a single project, it could be used as a starting template for new projects in a company that does smaller size projects
repetitive tasks are very common in the real world.
I must admit that i haven’t used codesmith apart from generating some gentle.net code (spielerei in my own time) but in my previous company the few web developers were delighted at the visual studio entreprise templates and macro’s that helped them automate “repetitive tasks” (add homepage, add header/footer control, add resource files)
I’m quite convinced that code generation is very useful today, the only problem with it is that it’s not used by the people it would be useful to.
For more basic needs, Gentle.Net takes nothing more than declaring some tags for reflection and a one-time change to the XML config file that sets what database to use. You can find it at source forge.
http://sourceforge.net/projects/gopf
I am using Gentle.NET on two “important” projects and so far it has reduced developing times by 30-40%.
You may not like them, but the developing time is decreased. Database access should be something “point and click”. That’s, IMO the biggest problem in .NET. I mean ADO.NET may be much more nice than Old ADO, but… it’s more of the same in one way or another.
Gentle may look weird, but try it, you’ll be surprised. And the best part it´s not the licence (LGPL, GPL) but the “huge” amount of Databases it works with. MySQL, JET, MS-SQL, Firebird, Oracle, Sybase, PostgreSQL…
I’ve seen some good mappers out there, but most of them only worked with MS-SQL.
Gentle claims to work under MONO.NET (tho I haven’t tried it yet).
http://www.theserverside.net/news/thread.tss?thread_id=29071
I agree. I have a major university application about to roll off the development process and it cut developement time by 50% for me. ADO.Net was so combersome for just simple database retreival that I needed that I just used ADODB through COM. I probably reduced my database code size by 80%. It’s been a very nice, stable product, so far.