Entity Framework 4 Mapping to POCOs
I've created a new entity data model of my database and manually created the POCO objects for this to map to and it all seems to work fine.
The problem is I now want to rename the properties in my POCO objects to differ from the field nam开发者_如何学Goes in the database e.g I want UserID rather than user_id, when I do this obviously EF then can no longer map an entity to the POCO object. Is there a way I can do this? Maybe by decorating the properties with attributes to say what maps to them?
You can change it in Entity Designer. Enity Data Model (EDM) contains 3 main parts:
- Conceptual model. What objects do you want to save.
- Storage model. What database structure do you have.
- Mapping. How to map objects to database.
POCOs are actually 'defined' in your conceptual model. Open Edmx file in Model Designer. Locate User entity there and change the name of the property.
Another approach to mapping POCOs to existing database structure is to use the Code First feature of EF CTP 4. Code First follows certain conventions to map POCOs to database tables/columns. This removes the need to maintain .edmx or mapping files making you more productive. To customize mapping as is done ala Fluent nhibernate, I believe EF CTP5 will have this feature.
Here is the blog article which you might useful.
http://theminimalistdeveloper.com/2010/07/28/how-to-map-pocos-to-existing-databases-in-entity-framework-4-0-code-first-and-asp-net-mvc-2/
精彩评论