Answer the question
In order to leave comments, you need to log in
Entity Framework Core how to add third party parameter when loading data from DB?
I am developing a server on RAGE MP (multiplayer for GTA 5). Decided to use EntityFrameworkCore but ran into this problem. This platform has a Client class with which you can control the parameters of the player and his character, I created an additional PlayerData class to make it more convenient to work with client data, and also add my properties there in the future. maybe the built-in ones are not enough. When a player disconnects, you need to save all class values to the database in order to load them later on connection, but due to the fact that many properties work by referring to the Client object, you need to immediately initialize the Client client property of the PlayerData class when creating an instance. But EFC works with constructors without parameters, and as a result, when initializing some properties, a runtime error occurs,
public int Armor
{
get
{
return client.Armor;
}
set
{
if (value < 0)
client.Armor = 0;
else if (value > 100)
client.Armor = 100;
else
client.Armor = value;
}
}
Answer the question
In order to leave comments, you need to log in
EFC (like EF) assumes that significant fields are projected into database columns. but as far as I remember my modest experience, a class can contain logic, not in getters / setters, but the methods work quite well. when they call it will be on your conscience
to save exactly what needs to be saved. and the logic can be very diverse:
- a property that is different from the real field (stored and restored), then the getters and setters of the property can operate with the saved field. I think so
- a clumsy option - use different classes for saving in the database, and for the entity in the game. design a squeeze for preservation, and a restoration from it
- or come up with your own by thinking about these suggestions of
good luck! ))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question