我正在尝试使用连接来获取数据,但是当我得到ParentHireGroupName
时它会显示错误。当我对这行代码做评论时它工作正常!
功能
public IList<RptFleetHireGroupDetail> GetFleetReport()
{
var fleetHireGroupDetailQuery = from vehicle in DbSet
join hgd in db.HireGroupDetails on
new {ModelID = vehicle.VehicleModelId, MakeID = vehicle.VehicleMakeId, CategoryId = vehicle.VehicleCategoryId, Year= vehicle.ModelYear }
equals new { ModelID = hgd.VehicleMakeId, MakeID = hgd.VehicleMakeId, CategoryId = hgd.VehicleCategoryId, Year = hgd.ModelYear }
select new RptFleetHireGroupDetail
{
HireGroupName = hgd.HireGroup.HireGroupName,
PlateNumber = vehicle.PlateNumber,
ParentHireGroupName = hgd.HireGroup.ParentHireGroup!=null? "kuch to hai":string.Empty,
};
return fleetHireGroupDetailQuery.OrderBy(fhgd => fhgd.FleetPoolName).ToList();
}
RptFleetHireGroupDetail
public class RptFleetHireGroupDetail
{
#region Public
public string HireGroupName { get; set; }
public string ParentHireGroupName { get; set; }
public string PlateNumber { get; set; }
#endregion
}
其他错误信息:
Cannot compare elements of type 'HireGroup'. Only primitive types, enumeration types and entity types are supported.