views:

241

answers:

3

I worked on a fairly large project a while back where we modeled the classes in Enterprise Architect and generated the (partial) POCO classes (complete with model-driven business rule validations), persistence (NHibernate mapping file) and DDL. Based on certain model attributes we could flag alternate generation strategies or indicate that a particular portion would be entirely hand-coded.

There was a good deal of initial investment, but it paid large dividends over the lifetime of a 15 developer, 3 year project.

I'm investigating doing something similar with the current Microsoft technology stack. The place I'm stuck is that class modeling is done with the VS 2010 UML tools, but logical data modeling is done with Entity Data Modeler.

Is it a reasonable path to use VS 2010 UML as the "single source of truth" and code generate the edmx files based on the class model? That's the inverse of the common path to create the entity model and use a POCO generator to generate classes. However, a good class model can be used to generate much more than just the properties so I tend to view it as a better choice than the entity model.

+1  A: 

It's always going to be a problem, as each modeling layer maps two disparate worlds. To have fully aware code, your generation system must have access to all mapping models. IOW, you can't simply declare one to be the "master", as each layer is a "real" perspective of the solution.

Mike Hanson
@Mike: We were pretty successful in the project I reference having a "single source of truth" in the UML model. Of course the code generation strategy had to be flexible (different stereotypes and "tagged values" (an Enterprise Architect thing I don't see in MS UML) could drive different generation strategies, and we had to leave room to make decisions by hand. We did still have a separate physical data model, but the logical data model (equivalent of EDM) could be seen in the UML model. Still, it's a good point that the worlds are very different.
Eric J.
As long as it can see a "version" of the data model, and talk to that interface point, then yes, the UML approach should work (assuming you want to put that much information into your UML diagrams).
Mike Hanson
+1  A: 

Entity Data Modeler is limited to a single diagram per model and becomes unusable in non-trivial scenarios. You can use UML profiles to extend class models for logical data modeling. It requires a significant investment of effort and time which may be justified on a 3-year 15-developer project.

Oleg Sych
+1  A: 

Yes, this is possible. No, there is nothing built in. To do this you'd need to write a VSIX which would consume the model and emit EDMX/code. This isn't necessarily hard, but you'd have to do it yourself. You'd also need a pattern or attributes for handling the modeling aspects which you might not have in your diagrams, just like you have to do for specifying key fields and the like when doing code-first modeling.

Craig Stuntz