Zaheer Moola
Zaheer Moola

Reputation: 133

Moving from EF-Model First to Code First

I'm extremely new to programming. Just above school level. I created a project using EF Model First only to realize after I cannot get it to use SimpleMembership for Login, etc.

I wanted to try and solve this problem whilst remaining model-first as I asked here: https://stackoverflow.com/questions/36552439/could-someone-explain-this-code-to-me-ef-model-first-mvc

However, due to lack of response I'm considering just migrating the project to code first. I know that it is possible but I've been following tutorials online to no avail.

Could someone please explain to me how to properly move to code first. I'm even willing to recreate the program if necessary as long as it does not take too long.

I'd really appreciate some help. Thanks

Upvotes: 0

Views: 106

Answers (1)

Joel Dykstra
Joel Dykstra

Reputation: 31

This really has been answered here.

I think you should really consider moving to ASP.NET Identity Membership, it's much more robust and has plenty of nice features without being difficult to manage. This is a really nice tutorial.

As for EF Code/Model first, you're thinking of them as something that defines your project; but really, they define a database CONTEXT. In other words, you can use both! Now don't get crazy, things can get sloppy quickly. But there is nothing that stops you from pulling in an existing set of tables and building models from them, but then adding another context to promote your classes into a database.

If you think of it as "switching" your project, you're getting it backward. And regardless, to get your models and database to sync, you need to either migrate your models or import your tables into EF. But it's a specific action you take, nothing happens magically. You COULD write your classes to perfectly mirror your database, create your EF models, and everything would work without you doing any direct connection (though you'd have a bit of a migraine afterward).

So don't worry about moving from one to the other. Just add a new context if you have a specific need to manage classes across different contexts.

But seriously, look at ASP.NET Identity to make all these problems go away...

Upvotes: 1

Related Questions