【发布时间】:2015-07-31 10:14:02
【问题描述】:
我正在开发 ASP.NET-MVC-5 应用程序。我有一个模型类,它具有名为 PropertyTpe 的导航属性,我需要使用 linq 通过加入在以下模型中作为外键作用的 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; }
}
【问题讨论】:
标签: c# linq asp.net-mvc-5 strongly-typed-dataset