我正在研究ASP.NET-MVC-5应用程序。我有一个模型类,它有一个名为PropertyTpe的嵌套属性,我需要通过将propertyTypeID作为外键加入propertyTypeID来添加它的值。我加入了LINQ,但我仍然错过了这个价值,我想我在这里错过了一些东西!
强类型模型的方法返回列表
public List<PropertyRentingPrice> GetAllPropertyRentingPrice()
{
try
{
using (var _uow = new PropertiesManagement_UnitOfWork())
{
var _records = (from _propertyRentingPriseList in _uow.PropertyRentingPrice_Repository.GetAll()
join _propertyTypeList in _uow.PropertyType_Repository.GetAll() on _propertyRentingPriseList.PropertyTypeID equals _propertyTypeList.PropertyTypeID
select _propertyRentingPriseList).ToList();
return _records;
}
}
catch { return null; }
}模型类
public class PropertyRentingPrice
{
public PropertyRentingPrice() { }
[Key]
[Column(Order = 0)]
[Display(Name = "Property Renting ID")]
public int RentingID { get; set; }
[Key][Column(Order=1)]
[Display(Name = "Housing Organization ID")]
[Required(ErrorMessage = "Require Housing Organization ID")]
public int HousingOrganizationID { get; set; }
[Key]
[Column(Order = 2)]
[Display(Name = "Property Type ID")]
[Required(ErrorMessage = "Require Property Type ID")]
public int PropertyTypeID { get; set; }
[Display(Name = "Cost Per Week")]
[Required(ErrorMessage = "Require Cost Per Week Based on Property Type")]
public decimal CostPerWeek { get; set; }
[Display(Name = "Cost Per Month")]
[Required(ErrorMessage = "Require Cost Per Month Based on Property Type")]
public decimal CostPerMonth { get; set; }
[Display(Name = "Currency")]
[Required(ErrorMessage = "Require Currency In Which Property Been Advertised, Type £ for British Pound")]
public string Currency { get; set; }
[Display(Name = "Maximum Occupancy")]
[Required(ErrorMessage = "Require Maximum Number Occupancy Based on Property Type")]
public int MaximumOccupancy { get; set; }
[Display(Name = "Bill Includes")]
[Required(ErrorMessage = "Require Yes/No if Property Rent Includes Bills")]
public bool Bill_Includes { get; set; }
public HousingOrganization HousingOrganization { get; set; }
public PropertyType PropertyType { get; set; }
}发布于 2015-07-31 10:23:30
我找到了以下答案;
更新linq;
var _records = (from _propertyRentingPriseList in _uow.PropertyRentingPrice_Repository.GetAll()
join _propertyTypeList in _uow.PropertyType_Repository.GetAll() on _propertyRentingPriseList.PropertyTypeID equals _propertyTypeList.PropertyTypeID
select _propertyRentingPriseList).Include(x=>x.PropertyType).ToList();在剃须刀代码循环中
@foreach (var item in Model._PropertyRentingPriceModel)
{
<tr>
<td>@item.PropertyTypeID</td>
<td>@item.RentingID</td>
<td>@item.PropertyType.Type</td>
<td>@item.CostPerWeek</td>
<td>@item.CostPerMonth</td>
<td>@item.Currency</td>
<td>@item.MaximumOccupancy</td>
<td>@item.Bill_Includes</td>
</tr>
}https://stackoverflow.com/questions/31743697
复制相似问题