此代码编译但会生成运行时错误。本质上,我只是在实体框架中执行存储过程并尝试返回单个对象。关于 w 的任何想法
代码:
public static TowingCustomerVehicle GetTowingCustomerVehicle(int vehicleID)
{
using (ProductServiceEntities context = new ProductServiceEntities())
{
TowingCustomerVehicle vehicle = (TowingCustomerVehicle)context.Vehicles
.Where(v => v.VehiclePK == vehicleID)
.Select(v => new TowingService2._0.Model.Towing.TowingCustomerVehicle
{
CurbWeight = (int)v.CurbWeight,
HitchSystemRating = (int)v.TowingCapacityMaximum,
FuelType = v.FuelType,
TopType = v.TopType,
TongueLoadRating = (v.TowingCapacityMaximum ?? 0),
IsCVT = v.IsAutoTransCVT ?? false,
DriveType = v.Driveline,
EPAClass = v.EPAClass,
Make = v.Make,
Model = v.Model
});
vehicle.AttachedWiring = context.IsAttachedWiring(vehicleID).Count() > 0 ? true : false;
return vehicle;
}
}
错误:无法将“System.Data.Objects.ObjectQuery`1[TowingService2._0.Model.Towing.TowingCustomerVehicle]”类型的对象转换为“TowingService2._0.Model.Towing.TowingCustomerVehicle”。