我不想每次都初始化每个字段,我想在构造函数中全部初始化,可以吗?
var districts = _districtRepository.FindBy(d => d.CityID == id).Select(d => new DistrictViewModel(d)).ToList();
楷模:
public class DistrictViewModel
{
public Int32 ID { get; set; }
public String Name { get; set; }
public DistrictViewModel()
{
}
public DistrictViewModel(District district)
{
if (district != null)
{
ID = district.ID;
Name = district.Name;
}
}
}