We have an entity type class that when it is converted to its dto class, I want a property to be set with additional calculations. Entity class:
public class Student
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public byte Score { get; set; }
}
Dto class:
public class StudentRankingDto
{
public int Id { get; set; }
public string Name { get; set; } // FirstName +" " +LastName
public string Rank { get; set; }
}
In Dto class, the rank attribute value is calculated based on a dictionary.
dictionary :
Dictionary<byte,string> Ranks { get; set; } = new Dictionary<byte, string>()
{
{0,"rejected" },
{1,"very weak" },
{2,"very weak" },
{3,"weak" },
{4,"weak" },
{5,"medium" },
{6,"medium" },
{7,"Good" },
{8,"Good" },
{9,"Excellent" },
{10,"Excellent" }
};
And considering that the dictionary may change later due to the logic of the program and it is necessary not to have a fixed dictionary inside Automapper and this dictionary must be sent to Automapper. Now my question is: how to assign the rank attribute based on the student’s score in Automapper by sending this dictionary?
And a more general question. If the value of the property to be calculated should be obtained from a database table, how is it possible to inject the database into Automapper with ef Core?
I tried to send an object based on the Automapper guide but it didn’t work