❔ Database with SQL (coming from a Rails background)
So for those that don't know Rails, we generate our model like this
rails g model product name:string
(just one attribute for the example)
Then in the console we go rails db:migrate
once the database is migrated, we enter the Rails console and start populating it. Here's an example.
Product.create(name: "Sweater")
Lo and behold. That just created a new product called "Sweater" and it's now in the database.
My question is can you do the same thing in the console with C# and ASP.NET?7 Replies
With EF Core, sure
It's a little bit more involved, but also lets you just not write any SQL
1. Create a class that describes your model
2. Add the
DbSet
to your DbContext
3. Create a migration
4. Apply the migration
5. Use it
There's no CLI for creating classes or seeding, thoughCould easily create one
Oh yeah
Really?
Because it is nice that I could seed the database and everything without having the site up and running.
Just place your database models and the dbcontext in a separate project
And have a console app that references them
And use that console app for seeding
ah okay
alright thank you!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.