渡されたTyreIDがCarTypeクラスの主キーではない「CarTypes」オブジェクトのリストを(2番目のメソッドから)正しく返すにはどうすればよいですか?たとえば、すべてのCarTypeのリストを返したいと思います、TyreIDが5の場合:
// GET api/CarTypes
public IEnumerable<CarTypes> GetCarTypes()
{
return db.CarTypes.AsEnumerable(); //This works fineCar
}
// GET api/CarTypes/5
public IEnumerable<CarTypes> GetCarTypes(long id)
{
CarTypes cartypes = db.CarTypes.Select(t => t.TyreID == id).AsEnumerable();
if (roomtypes == null)
{
throw new HttpResponseException(Request
.CreateResponse(HttpStatusCode.NotFound));
}
return cartypes;
}
現在、エラーが表示されています。
タイプ「System.Collections.Generic.IEnumerable」を「MvcApplication4.Models.CarTypes」に暗黙的に変換することはできません。明示的な変換が存在します(キャストがありませんか?)
また、クエリでSelect / SelectMany / Whereを使用するかどうかは重要ですか?