Can ADO.NET Entity Framework be used with an existing model?
I have an existing model for my project. I would like to switch to Entity Framework, but I don't want to replace my model with a model generated from EF.
Also, my model is very different from my database schema, so any chance of using the model generated from EF and doing all the necessary refactorings seems too difficult.
Is there any way to have an existing domain, an existing database, and use EF only to add methods to my domain to enable the O / RM layer?
a source to share
In .NET 3.5SP1, then the answer is a big fat "no" I'm afraid. In .NET 4.0, the story looks more promising, with the introduction of POCO support (which will hopefully allow you to use your own objects, although I haven't tried it on the public beta yet).
Note that you can do POCOs (with your own objects) with LINQ-to-SQL using an external mapping file (and supplying the object DataContext
), but the tools don't help you do that (it wants to use default code generation).
For now, perhaps NHibernate (and similar) is your best bet.
a source to share
You can download the Entity Framework if you are an MSDN subscriber. It supports the POCO object you are talking about and for which EF 1.0 has been heavily criticized.
The ADO.NET development team recently posted @ POCO in Entity Framework: Part 1 - Experiences to get you right on the track.
From my experience with the EFPocoAdapter (predecessor to EF 4.0), I am happy to suggest EF 4.0.
You also get support for some cool n-tier scripting, which means you can push your objects to another tier that can modify and return them, and you can still save them to the database. And the other layers don't have to know anything about the entity infrastructure, so you get a clear separation of concerns.
a source to share