这是有问题的两种方法
我想返回 csVehicle 和 csDistributor 的对象,因为我下面的代码只返回 csVehicle
请帮忙
public List<csVehicle> get_All_Vehicles()
{
var objv = new List<csVehicle>();
IDataReader dr = null;
var objdal = new csDAL();
dr = objdal.executespreturndr("sp_Get_All_Distributor");
while (dr.Read())
{
var d = new csDistributor(); // I put this here so that I can use the propDistrbutorId
var v = new csVehicle();
populate_Data(dr, d,v);
objv.Add(v); //It only adds object of csVehicles and csDistributor is not added
}
return objv; // csDistributor is not returned
}
populate_Date 方法将数据添加到两个对象 csDistributor 和 csVehicle
private void populate_Data(IDataReader dr, csDistributor d, csVehicle v)
{
v._vehicleRegNo = dr["VehicleRegNo"].ToString();
d.propDistrbutorId = Convert.ToInt32(dr["DistrbutorId"]);
}