이 코드는 컴파일되지만 런타임 오류가 발생합니다. 기본적으로 엔티티 프레임 워크에서 저장된 proc을 실행하고 단일 객체를 반환하려고 시도합니다.Entity-Framework InvalidCastException
이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;
}
}
ERROR : 유형의 개체를 캐스팅 할 수 없습니다 'System.Data.Objects.ObjectQuery`1 [TowingService2._0.Model.Towing.TowingCustomerVehicle]'를 입력하는 코드
승에 대한 모든 아이디어 'TowingService2._0.Model.Towing.TowingCustomerVehicle'.