내가 내 전체 데이터베이스에 대한 컨트롤러가, 코드는 다음과 같습니다 : 당신은 내가 하나의 컨트롤러에서 여러 된 IQueryable을 볼 수 있듯이, 각각 다른 테이블을 쿼리하나의 컨트롤러에 여러 IQueryable이 있습니까?
public class YogaController : DbDataController<Yoga.Models.YOGAEntities>
{
public YogaController()
{
}
public IQueryable<Yoga.Models.Action> GetActions(int BugId)
//GetActions retrieves "actions" table from the db, not Actions in MVC term
{
return DbContext.Actions.Where(x => x.FK_BugsID == BugId);
}
public IQueryable<Yoga.Models.Label> GetRequiredLabels()
{
return DbContext.Labels.Where(x => x.IsRequired == true);
}
public IQueryable<Yoga.Models.Role> GetRoles()
{
return DbContext.Roles;
}
public IQueryable<Role> GetRoles2() //TODO: finish this
{
return DbContext.Roles.Where(x => x.RoleID == 1);
}
public IQueryable<Tag> GetTags(int actionid)
{
return DbContext.Tags.Where(x => x.J_Tags.Any(y => y.FK_ActionID == actionid));
}
}
. 그것은 금지 된 것입니까? 내가 localhost/api/Yoga/GetActions
또는 localhost/api/Yoga/GetRequiredLabels
에 갈 때 때문에 나는 오류 메시지 :
Multiple actions were found that match the request:
System.Linq.IQueryable`1[Yoga.Models.Label] GetRequiredLabels() on type Yoga.Controllers.YogaController
System.Linq.IQueryable`1[Yoga.Models.Role] GetRoles() on type Yoga.Controllers.YogaController
System.Linq.IQueryable`1[Yoga.Models.Role] GetRoles2() on type Yoga.Controllers.YogaController
내가 하나 된 IQueryable하지만 모두 해제
, 결과가 잘 나왔다.나는 비슷한 문제에 대한 봤 거든 내 라우팅 설정을 확인, 거기에 컨트롤러 경로와 이름에 충돌이 있습니다.
내 경로 (기본값 생성) :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//routes.MapRoute(
// name: "Default",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
어떤 아이디어?
조치 방법의 반환 유형으로 IQueryable을 반환하는 이유는 무엇입니까? – Shyju
MVC4를 사용하여 본 튜토리얼입니다. http://goo.gl/mqzDD 프론트 엔드가 upshot.js를 사용하고 IQueryable을 직접 처리하는 곳입니다. 정확한 메커니즘을 잘 모르겠습니다. – Bonk
IQueryable을 반환하면 해당 작업의 쿼리 문자열에 OData 필터와 옵션을 사용할 수 있습니다. – diaho