DEV Community

Cover image for Object-Relational Mapping & Code First Migration with Entity Framework Core

Object-Relational Mapping & Code First Migration with Entity Framework Core

Patrick God on February 19, 2020

This tutorial series is now also available as an online video course. You can watch the first hour on YouTube or get the complete course on Udemy....
Collapse
 
ryanpd423 profile image
Ryan • Edited

Great tutorial - thank you for sharing!

Might be worth mentioning that as your models change you'll need to rerun the dotnet ef migrations add {InsertName} command THEN run dotnet ef database update to run the latest migration and have your database updated.

Again, props to you for making this tutorial. It is awesome!

  • Ryan
Collapse
 
informagico profile image
Alessandro Magoga

Hello again Patrick, it was really enjoyable to follow these articles.
Can't wait to see more coming and also I would like to suggest you to think about some other implementations other than MS SQL Server for users like me that are macOS-oriented (yes, I know that I can fire up a VM or Docker but hey, I'm lazy after all 😂).
I tried by myself to use SQLite, and it worked, but I can see something is missing 😁

This was a very good way to spend my Sunday, I feel like going from zero-to-hero in .NET Core.

Collapse
 
_patrickgod profile image
Patrick God

Hello again Alessandro,
Thank you so much. Your words mean a lot to me. I really appreciate it.

I totally understand your "laziness". ;)

Implementing other databases like SQLite, MariaDB or even NoSQL databases like MongoDB is a topic I will keep in mind!

Apart from that, I will make a video tutorial of this whole tutorial series and maybe add those implementations of other databases to these videos. If you're interested, let me know.

Talk soon,
Patrick

Collapse
 
samselfridge profile image
samselfridge

If anyone else is feel slightly less lazy, here's a guide for getting it up and running with docker on OSX:

database.guide/how-to-install-sql-...

Collapse
 
samselfridge profile image
samselfridge • Edited

For anyone following on MacOS / OSX - you can use this docker guide to get setup:
database.guide/how-to-install-sql-...

Also I was having issues with my connection string. I suspect that 'trusted_connection' is a windows only thing, so I was able to get mine working using this connection string:

"Server=localhost,1433; Database=devDotNet; User Id=sa; Password=MuchStrengthSoPassVeryWord;"

Collapse
 
_patrickgod profile image
Patrick God

Thank you very much for sharing this! :) I think your post will help lots of maxOS users.

Collapse
 
mikependon profile image
Mike Pendon (Zym)

Nice article mate. Anyway, in the world of micro components and fast-faced development, are you really spending time too much for such kind of bootstrapping? I guess, it is a bit too much for a single developer to always do this without the help of this kind of tutorial.

Why not install the library and use it right away (in seconds) and spend most of the time into a much more productive activity.

We loved micro ORMs due to its performance, flexibility and simplicity. I am also an author of ORM named RepoDb, an ORM that consist the missing pieces of Dapper (as the benefits), plus being the fastest right now. In either way, micro-ORM are both worth trying.

Collapse
 
_patrickgod profile image
Patrick God

Hey Mike,

Thanks for your comment. It isn't that much work, actually. You do it one or two times and you already got the hang of it and are able to enjoy the advantages of Entity Framework (Core).

If you want to build an MVP real quick, of course you can also use a solution like yours or use online web development platforms like Firebase.

Many corporations stick to .NET Core, though, and like to have complete control of the code.

So, what you want to use in the end, is totally up to you.

Have a great day!

Take care,
Patrick

Collapse
 
samselfridge profile image
samselfridge • Edited

If you're continually getting 'Build failed.' message when trying to set up your 'dotnet ef migrations' - Make sure you stop the debug server.

If it's running it prevents files being copied that the migration needs. Took me wayyy to long to put a --verbose on there and find out why.

Collapse
 
mr_daf profile image
Dave Van Meerbeeck

Hi Patrick,

i like these articles a lot and am curious for the next parts.
Thanks for sharing your insights :-)

Collapse
 
_patrickgod profile image
Patrick God

Hi Dave, Thank you very much to you as well. I really appreciate it! :)

Collapse
 
nicefella profile image
Ismail Baygin

Hi Patrick, these are amazing articles. I like your teaching style very much.
Can't wait to read the 6th part :)

Collapse
 
_patrickgod profile image
Patrick God

Hi Ismail, Thank you very much. I really appreciate your kind words! :)