2

I'm putting together a new ASP.NET MVC project and have already designed and build my domain model and my DB schema.

I've had a look round and haven't found a clear step-by-step guide that shows me how to use the Entity Framework 5 to map my domain objects to the DB tables.

I just added a new .edmx file and generated a model from the DB, but what do I do now in order to map my model to this? I am trying to avoid having any EF code or data annotations anywhere other than in my data access layer (I'm using the repository pattern and my service layer simply calls into the repository and gets back my own non-EF domain objects).

Should I avoid EF altogether? I thought I would give it a whirl, but I want it to be as unobtrusive as possible and just let me be in full control of my DB and domain.

Thanks.

1 Answer 1

2

You should consider Entity Framework Code First if you wish to work with code directly, and not the designer.

You can use Code First with an existing database. In fact, Entity Framework Power Tools (a Visual Studio Extension) can generate your DTO's from an existing database, which you can then tailor to your needs.

You should also consider using the fluent API for configuring your mappings, rather than data annotations for the reasons you gave.

Two books that cover the details are Programming Entity Framework: Code First, and Programming Entity Framework: DbContext, both by Julia Lerman and Rowan Miller.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - think I've got what I need now with a mixture of DbContext and the Fluent API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.