I don't really know if this makes any sense but I'm gonna give it a try cause I'm not getting anywhere on my own and I need to learn.
I have this code:
List<User> topuser = db.Database.SqlQuery<User>("SELECT TOP 5 * FROM Users ORDER BY DimensaoRede DESC").ToList();
And I have a method that converts objects of the type "User" to UserModel like this:
I loop through the list and convert the users in it
public static UserModel UserToUserModel(User user){
UserModel model = new UserModel
{
id = user.UserId,
AdvanceLevel = user.AdvanceLevel,
DimensaoRede = user.DimensaoRede,
FortalezaRede = user.FortalezaRede,
NormalLevel= user.NormalLevel,
UserName = user.UserName
};
if (user.Facebook!=null) model.Facebook= user.Facebook;
if (user.LinkedDin != null) model.LinkedDin = user.LinkedDin;
if (user.Status != null) model.Status = user.Status.Descrição;
if (user.Nome != null) model.Nome = user.Nome;
model.Tags = user.Tags.Select(s => s.Nome).ToList();
return model;
}
But an User when he is created the Tag list "Tags" is null so when he queries the Database the List Tags comes as Null.
So when the application runs this:
model.Tags = user.Tags.Select(s => s.Nome).ToList();
It breaks because it is null. How can i solve this problem?