我正在尝试合并三个列表,这些列表将始终从我需要将这三个列表合并到一个列表中的资产列表中返回某些属性。但并非所有主列表的字段都填写
List<Asset> allAssets = new List<Asset>();
List<Asset> _vheiclesList = new List<Asset>();
_vheiclesList = getallVechiclesForSlate();
List<Asset> _propertyList = new List<Asset>();
_vheiclesList = getAllPropertyForSlate();
var AllAssets = allAssets.Concat(_vheiclesList)
.Concat(_propertyList)
.ToList();
_createCase.Assets = AllAssets;
但是我得到一个可以为空的对象必须有一个值,我不知道为什么。
public List<Asset> getAllPropertyForSlate()
{
try
{
List<tbl_Property> _property = new List<tbl_Property>();
Asset _asset = new Asset();
_property = dal.GetPropertiesById(caseid);
foreach (var property in _property)
{
_asset.Id = Guid.NewGuid();
_asset.AssetType =(int) slateExportsConstants.AsssetTypes.Property;
_asset.Description = property.addressLine1 + " " + property.addressLine2 + property.county + " " + property.country + " " + property.postCode;
_asset.CurrentValue =(int) Math.Round(Convert.ToDecimal(property.valueOfProperty.Value));
string valuationDateIso = JsonConvert.SerializeObject(property.dateofValuation.Value);
_asset.ValuationDate = valuationDateIso;
if (property.thirdPartyOwner == new Guid(fhsConstants.fhsPartner))
{
_asset.Owner = (int)slateExportsConstants.Applicant.Applicant2;
}
else if (property.thirdPartyOwner == new Guid(fhsConstants.fhsExPartner))
{
_asset.Owner = (int)slateExportsConstants.Applicant.Joint; }
if(property.isHomeAddress==true)
{
_asset.Home =(bool) property.isHomeAddress;
}
if (property.housingAssoication == true)
{
_asset.HousingAssociation = property.housingAssoicationShare.ToString();
}
if (property.isHomeAddress == true)
{
_asset.Home = true;
}
_asset.Equity = Convert.ToInt32(property.valueOfEquity);
_asset.IsSharedOwnership = property.coOwnerdByAnyOtherParty;
_assets.Add(_asset);
}
return _assets;
}
catch(Exception ex)
{
return null;
}
}
public class Asset
{
public Guid Id { get; set; }
public string Description { get; set; }
public int CurrentValue { get; set; }
public string ValuationDate { get; set; }
public int Owner { get; set; }
public int OutstandingFinance { get; set; }
public int FinanceAccountHolder { get; set; }
public int FinanceMonthlyPayment { get; set; }
public DateTime FinanceEndDate { get; set; }
public bool Home { get; set; }
public int AssetType { get; set; }
public DateTime FixedPeriodEndDate { get; set; }
public int ValuationSource { get; set; }
public int Equity { get; set; }
public bool IsSharedOwnership { get; set; }
public string HousingAssociation { get; set; }
public int HousingAssociationShareOfPropertyPercent { get; set; }
public bool BeneficialInterest { get; set; }
public int JointOwner1 { get; set; }
public int JointOwner2 { get; set; }
public string JointOwner3 { get; set; }
public int RentalIncome { get; set; }
public string AccountNumber { get; set; }
public string PropertySecuredAgainstId { get; set; }
public string FinanceCompany { get; set; }
}
答案 0 :(得分:1)
是否因为这行:
_vheiclesList = getAllPropertyForSlate();
应该是:
_propertyList = getAllPropertyForSlate();