ace
ace

Reputation: 215

Entity Framework 4.0 Mapping POCOS with different property names from db fields names

I'm a newbie to ADO.Net Entity framework 4. I have a set of pocos which I need to map to a legacy database. The problem is that the db field names are different to the poco property names. eg. db field name = 'cusID' and poco property = 'CustomerID'. What is the best way to map these?

Upvotes: 2

Views: 1146

Answers (2)

Bikal Lem
Bikal Lem

Reputation: 2423

Entity Framework CTP4 has a new feature called Code First that allows you to map POCO property members to database table column names. This blog article may be what you are looking for,

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/

Additionally, EF CTP 5 - which will be released in the next few weeks - has a better API to fluently configure your own conventions to map your POCO domain classes to existing database structures.

Hope this helps.

Update Here is the new article that discusses how to achieve this in EF4 CTP5

Upvotes: 1

Alex James
Alex James

Reputation: 20924

This is exactly the problem EF mapping is designed to solve.

Your POCO class need to match your 'conceptual model'... Not your 'data model'.

If in EF you build your model from the database you simply need to rename your entity properties. Doing this changes the conceptual model - to match your POCO classes - but leaves the storage model unchanged, and sets up the appropriate mappings.

Upvotes: 5

Related Questions