3

I am in the process of writing a new web application. I am using ASP.NET MVC 3 with Entity Framework code first. The database is automatically created and everything looks good so far.

However, we already have an existing database that holds details of all our current users and I want to be able to retrieve data from this database table in my new project. Is this possible using EF Code First and if so, how would I go about this?

Thanks in advance.

0

2 Answers 2

3

Description

I have done the same a few months ago. You can map your Model to an existing Database. Scott Guthrie has blogged about it. You can use the Enity Framework Power Tools to create your models from your existing Database.

More Information

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

2 Comments

Thanks for the reply. Is it possible to just map to existing database and use EF code first to automatically create a different database?
Yes but you need 2 Different DbContext for that. One for your existing db and one for the new automatically generated database.
1

Yes, it's possible. Have a look at Scott Gu's blog where he describes how to do it. http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx

Comments

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.