views:

61

answers:

3

Hi Everyone

Is it possible to create the database from the classes with entity framework 4.0? I found many tutorials on how to do it the other way round. But since we have already implemented and tested all classes of the domain we'd like to avoid changing them to much. If I used the wrong keywords in Google I'd appreciate you could post a link.

Cheers, CA

A: 

Yes, it is possible. The approach is known as "model-first".

You define your entities with designer then call for "Generate database script" or something. Run this SQL against a database and it will create tables and relationships.

Developer Art
I found enough documentation on how to do that. But I have classes not entities. So far I didn't find a way to create entities from classes. That's the problem.
Anonymous Coward
@Anonymous Coward: I'm not quite sure what is it exactly that you wish to do. Could you be please more specific? If you wish to generate database from a set of classes, consider first whether they provide sufficient information to generate tables and relationships. Without defining relationships explicitly or implicitly, it may not be possible to create a fully functional database schema. Mirror classes to tables one-to-one yes, but not beyond that.
Developer Art
I was told to generate a database from a set of classes using Entity Framework. You got it right. Since someone from my team attended a tech days presentation which convinced him that this is possible I'm stuck with proofing the opposite or finding a way to do it.The ideal solution for me would be to generate an (incomplete) entity model from my class diagram which I could refactor to fit my needs.
Anonymous Coward
@Anonymous Coward: Sorry to hear that. I'd suggest you put it forward that this strategy is not feasible, not just for EF or in general. If there are no entity relationships defined for a framework to pick up, then there is no way for it to infer semantics from the code and come up with suggested relationships. Database design has always been an important if not strategic component of development process, it has to be done manually with proper understanding of each unique case.
Developer Art
A: 

This is quite easy to do with Fluent NHibernate using Auto Mapping. You could also use Fluent Mapping if you want more control over how your entities are mapped, but this will require writing mapping classes. It shouldn't affect your existing classes though.

alimbada
A: 

While looking up an other question on Stackoverflow I found an the solution for my problem: http://stackoverflow.com/questions/2478081/entity-framework-4-poco-where-to-start/2498998#2498998

Anonymous Coward