你们中的任何人都可以帮我解决这个问题吗?将“carsList”变量转换为“_vehicleList”时出现此错误
无法将类型为“System.Data.Linq.DataQuery”的对象转换为类型“System.Collections.Generic.List`1[VehicleDAOModel]”。
Linq.DataQuery 是否必须与 VehicleDAOModel 中的属性匹配?
我的代码:
public class VehicleDAOModel
{
[Display(Name = "Id")]
public int _Id { get; set; }
[Required]
[Display(Name = "Year")]
public string _year { get; set; }
[Required]
[Display(Name = "Make")]
public string _make { get; set; }
[Required]
[Display(Name = "Model")]
public string _model { get; set; }
[Required]
[Display(Name = "Trim")]
public string _trim { get; set; }
}
// LINQ TO SQL CODE
var dataContext = new VehicleModelL2SQLDataContext();
var carsList = from v in dataContext.Vehicles
select v;
_vehicleList = (List<VehicleDAOModel>)carsList;
public List<VehicleDAOModel> _vehicleList = new List<VehicleDAOModel>();
尝试了以下但没有奏效:carsList.ToList(); (X) carsList.AsEnumerable().LoList(); (X)
先感谢您。