I have a .NetCore 3 Entity Framework controller that returns an object like this:
var games = await _context.Game
.Select(x => new GameEntity
{
Id = x.Id,
Title = x.Title,
GameCharacterClasses = x.GameCharacterClasses
}).ToListAsync();
The GameEntity class looks like this:
public partial class GameEntity
{
public GameEntity()
{
GameCharacterClasses = new HashSet<GameCharacterClasses>();
}
public long Id { get; set; }
public string Title { get; set; }
public virtual ICollection<GameCharacterClasses> GameCharacterClasses { get; set; }
}
GameCharacterClasses is an array with the Id of the game and the Id of the characterClass.
The thing is, I really need the characterClass name and not the Id of the game or characterClass.
Is there a way to make a code-based table or variable so I can look-up the needed characterClass name based on the Id?
Like, if the GameCharacterClasses array contains the Ids(GameId, CharacterClassId)
[(5, 1), (5, 4), (5, 7)]
Then the array should contain
'Wizard', 'Fighter', 'Cleric'?
I tried using a complicated if/then tree, but it got out of hand.
I'd like to have some type of look-up based variable if that's possible...like:
0 : Thief
1 : Wizard
2 : Paladin
3 : Assassin
etc...
Is there a way to do that in c#?
Thanks!