OnModelCreating dont work in Memory Database
I try create API for list menu.
When i call endpoing /api/menu i see Console log, but return empty sandwich and extra.
Obs: When i use EnsureCreated, workly
7 Replies
to clarify, you're saying that when you call EnsureCreated that it works correctly?
that is intended behavior, in order to apply changes you've made to your database model you either need to call EnsureCreated or use migrations
Data Seeding - EF Core
Using data seeding to populate a database with an initial set of data using Entity Framework Core
you should be using migrations if you have any plans to evolve the model over time
Yes, i tried set directly in controller the método EnsureCreated and i See The console log two times, but return the correctly data of sandwich and extra
😅Ah ok, it's my first time with C# and I didn't know that
I have one more question, if you can answer
I can set EnsureCreated when i started program?
You can but it won't work if the database already exists
Migrations are a much better choice for that
Without a doubt, but I'm doing for a job and they specified that I need to use the in-memory database😠kkkkk but the article you sent me seems very useful, I will try to implement it, thank you!
with help Chat GPT, i did this
Console log show 2 times, but dont duplicate data. I ignore because its working
Why do they want you to use in-memory?
EF’s in-memory database is a trap.