views:

154

answers:

3

I have designed some classes using Visual Studio class diagramming. Now I would like to persist this data using ORM and maybe other persistence mechanisms. I am wondering if there is a way to generate the SQL based on the properties in my classes, since they fairly well represent the database structure needed. This would save me a lot of manual SQL typing, and give me a nice start.

I didn't start with the database model because I want to have my persistence decoupled from the actual "domain layer" (not sure if this is the correct naming).

The ORM mapper(LLBLGen) can then generate the coded based on this schema, and I'll only have to map the generated objects to my persistence interface.

Is the a good idea, or am I on the wrong path here?

I have found a tool that seems to do the job(MindScape LightSpeed), but unfortunately it's only available for VS2008.

+1  A: 

It depends. If the project is small, and you have a tight deadline. Sure. However, generated code is almost always less maintainable than hand written code. This is the same for database schema generation. Have a look at your project scope. Maybe even generate the database, and see if you like how it looks. Then decide for yourself. Re evaluate for your next project. One size doesn't fit all.

Matthew Vines
This is indeed a small project, with a relatively flat database schema. Any idea on how to do this? (I could do it myself using reflection, but there wouldn't be any time saved ;) )
Robert Massa
I've done this on the cheap with Sparx Enterprise Architect. Import the classes, then use the Transform command to transform them into DDL. Get a trial version if this is a one-time hack.
John Saunders
I would definitely use a 3rd party ORM over trying to create my own solution. LLBLGen isn't a bad choice. You could also use NHibernate.
Matthew Vines
+1  A: 

It's a bad idea. Class design and database design are not the same thing.

Personally, I do my design at the conceptual level with NORMA, a free Visual Studio add-in. It will generate the schema from the conceptual model, and can also generate classes.

The classes it generates are a bit heavy for my tastes, but it turns out the code generation can be customized, if you don't fear XSLT.

Because of the nature of Object-Role Modeling, the constraints you place on the model can be used to infer both the database schema, and a "class" model as well.

John Saunders
I'll give NORMA a try, thank you.
Robert Massa
+4  A: 

There are many ORMs that can generate database schema from domain model classes. Moreover there are some ORMs that are designed especially for such way of development. It is "Model First" or "Code First" concept, and some people think that it is a future of database applications development, since LINQ is replacing SQL now. For example next version of Entity Framework will fully support this concept. I can recommend to try DataObjects.Net, it automatically generates and upgrades database schema and supports LINQ queries.

Alex Kofman
Thank you for your clarification Alex, I will check out do.net as well!
Robert Massa