I have static method which returns me as it’s name says data from domain model.
public static List<PropertyViewModel> FromDomainModel(List<Property> x)
{
List<PropertyViewModel> dataVm = new List<PropertyViewModel>();
foreach (Property p in x)
{
dataVm.Add(new PropertyViewModel(p));
}
return dataVm;
}
Bellow is viewmodel which above FromDomainModel calls
….other properties …
public List<Photo> Photos { get; set; }
and first contructor
public PropertyViewModel(Property x)
{
Id = x.Id;
...
List<Photo> Photos = new List<Photo>();
foreach (var item in x.Photos)
{
Photos.Add(item);
}
}
On debug mode I’m having collection of Photos until it reaches the line in FromDomainModel() method
List<PropertyViewModel> dataVm = new List<PropertyViewModel>();
on debug in line dataVm.Add(new PropertyViewModel(p)); p actually holds properly collection.
Question is why is not passed inside list dataVm.
You’re hiding the property Photos by declaring a local variable with the same name on this line:
By using the type name
List<Photo>before the namePhotos, you are declaring a new variable that is hiding the Property.You can fix this by using the actual property:
or, to be even more specific: