linq to sql 类型转换
var changecar = (Car)DataCar.Car.Where(C => C.CarNumber == APPLY.CarNumber);
Car是一个表,我想修改表中某字段的值,
我的思路是先查询到某条记录,然后修改该记录某字段的值,可是提示IQueryable类型无法转换为Car类型
------解决方案--------------------var changecar = DataCar.Car.Where(C => C.CarNumber == APPLY.CarNumber);
foreach(var car in changecar )
{
car.name="aaa";
}
DataCar.SubmitChanges();
如果CarNumber 唯一,可以这样:
var changecar = DataCar.Car.FirstOrDeafult(C => C.CarNumber == APPLY.CarNumber);