C
C#5d ago
Tratt

.NET Core OnModelCreating gives me error

Hi, ive always used this code but now the highlighted code crashed the Update-Database when I try to Add-Migration and Update-Database. If I remove the highlighted code it works. I cant see whats wrong here, is it something new with .NET 8 that makes it not work?
No description
12 Replies
Tratt
TrattOP5d ago
Im trying to creating two roles in the context, using Identity
Unknown User
Unknown User4d ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4d ago
If you have no further questions, please use /close to mark the forum thread as answered
Tratt
TrattOP3d ago
No description
Tratt
TrattOP3d ago
how do I open it again?
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3d ago
The error is because you are seeding data with Guid.NewGuid(). This means that when OnModelCreate runs the guid will be different every time (i believe a similar issue can happen when using DateTime.Now). If this is an existing code base (or if too lazy - if its a personal project) then you can simply suppress the error and fix later. If possible though you should change the seed data to use an explicit non changing GUID.
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3d ago
Just confused, are you saying that you think hardcoding the GUID is bad practice or using GUIDs as ids?
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3d ago
ah, i agree. Its also more performant than GUIDs during scanning but meh people like the GUIDs as Ids - more power to them
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?