Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:39:17+00:00 2026-06-01T03:39:17+00:00

I have static method which returns me as it’s name says data from domain

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:39:19+00:00Added an answer on June 1, 2026 at 3:39 am

    You’re hiding the property Photos by declaring a local variable with the same name on this line:

    List<Photo> Photos = new List<Photo>();
    

    By using the type name List<Photo> before the name Photos, you are declaring a new variable that is hiding the Property.

    You can fix this by using the actual property:

    Photos = new List<Photo>();
    

    or, to be even more specific:

    this.Photos = new List<Photo>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static method which sets a variable: static String[] playersNames; public static
I have a HashMap<String,String> and there is a static method which returns this map
I have a static method I have no control over: MyUtils.getServiceURL() which returns a
I have a public static method string SomeMethod(string message) inside a SomeClass class which
I have a static web method which returns an object and this object has
I have a static method 'findAll' on a model which basically gets all rows
I have a class with static method which has a local static variable. I
I have a static method that takes a parameter and returns a class. the
I have a method which returns an IEnumerable<> which it builds up using the
I have a data access layer which returns an IDataRecord. I have a WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.