Pilvinen
Pilvinen
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
But why is it an anti-pattern passing the dbContext as a parameter to a function?
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Which makes it even harder.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
This is actually my first time ever using databases from C#.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Because it's now starting to feel silly why it even exists separately.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Oh so I would just relay it forward .. or maybe combine Configuration.cs with ConfigurationDataService.cs 🤔
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
I mean, what options do I have?
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
What's the proper way then?
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Really?
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
But apparently it was not a good idea.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Which is why I was doing that in the first place.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
I was trying to get rid of database specific calls in my code.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
So now they would share the same context.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
public static void SetDeckBack(int value) {

using (var dbContext = new GameDbContext(Paths.GetGameDatabaseFilePath())) {
// Get the player profile id for the active profile.
Guid playerProfileId = GameState.GetActivePlayerProfileId();
// Get the configuration data from the database.
ConfigurationData configurationData = ConfigurationDataService.LoadData(playerProfileId, dbContext);

// Modify the configuration data in the database data set.
configurationData.DeckBack = value;

// Save the changes to the database.
ConfigurationDataService.SaveData(configurationData, dbContext);
}
}
public static void SetDeckBack(int value) {

using (var dbContext = new GameDbContext(Paths.GetGameDatabaseFilePath())) {
// Get the player profile id for the active profile.
Guid playerProfileId = GameState.GetActivePlayerProfileId();
// Get the configuration data from the database.
ConfigurationData configurationData = ConfigurationDataService.LoadData(playerProfileId, dbContext);

// Modify the configuration data in the database data set.
configurationData.DeckBack = value;

// Save the changes to the database.
ConfigurationDataService.SaveData(configurationData, dbContext);
}
}
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
I mean like this:
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
I will inject the dbContext to fix that.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Yes, that's what I meant.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
As you suggested.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
I will try to inject the dbContext to get around not using a single context.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
Update(). The one I commented out there.
80 replies
CC#
Created by Pilvinen on 11/4/2024 in #help
Trying to learn EF Core
This works? Why? What's the difference?
80 replies