Carlos David
Carlos David
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
with help Chat GPT, i did this
var app = builder.Build();

# region Seed de dados
using (var scope = app.Services.CreateScope())
{
// Para banco de dados na memória é necessário fazer na mão utilizando o EnsureCreted
// Fonte: https://learn.microsoft.com/en-us/ef/core/modeling/data-seeding
var context = scope.ServiceProvider.GetRequiredService<Context>();
context.Database.EnsureCreated();
}
# endregion
var app = builder.Build();

# region Seed de dados
using (var scope = app.Services.CreateScope())
{
// Para banco de dados na memória é necessário fazer na mão utilizando o EnsureCreted
// Fonte: https://learn.microsoft.com/en-us/ef/core/modeling/data-seeding
var context = scope.ServiceProvider.GetRequiredService<Context>();
context.Database.EnsureCreated();
}
# endregion
Console log show 2 times, but dont duplicate data. I ignore because its working
15 replies
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
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!
15 replies
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
I can set EnsureCreated when i started program?
15 replies
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
I have one more question, if you can answer
15 replies
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
😅Ah ok, it's my first time with C# and I didn't know that
15 replies
CC#
Created by Carlos David on 8/12/2024 in #help
OnModelCreating dont work in Memory Database
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
15 replies