MVC 및 LINQ에 익숙하지 않으며 할당 된 새 프로젝트에 AngularJs 및 MVC를 사용하는 방법을 배우고 있습니다. 그래서 나는 온라인 비디오를 통해 이러한 기술을 배우고 있습니다. 교사는 코드 첫 번째 접근법을 사용하므로 Visual Studio는 튜토리얼 모델과 일치하는 모든 필요한 파일과 데이터베이스를 만듭니다. 반면에 이미 데이터베이스가 있고 API를 만들었습니다. DB에 대해 REST 조작을 수행하십시오. 내가LINQ를 사용하여 IEumerable을 검색 및 정렬
public IEnumerable<Todo> GetTodos()
{
return Models.DbStoredProcModel.GetAllTodos.GetAllTodoEntryStoredProcedure();
}
아래에이 코드를 실행하면 그래서이
그래서 지금까지 내 JSON 출력이 우리의 코드 접근 방식에도 불구하고 비디오 자습서와 일치 같은 JSON 출력을 반환 다른.
public IEnumerable<Todo> GetTodos(string q= null,string sort = null, bool desc = false, int ? limit = null, int offset =0)
{
var result = ((IObjectContextAdapter)db).ObjectContext.CreateObjectSet<Todo>();
IQueryable<Todo> items = string.IsNullOrEmpty(sort)
? result.OrderBy(o => o.Priority)
: result.OrderBy(String.Format("it. {0} {1}", sort, desc ? "DESC" : "ASC"));
if (!string.IsNullOrEmpty(q) && q != "undefined")
items = items.Where(t => t.Text.Contains(q));
if (offset > 0) items = items.Skip(offset);
if (limit.HasValue) items = items.Take(limit.Value);
return items;
}
이 그를 검색을 수행하고 반환 된 데이터에 대한 작업을 정렬 할 수 있습니다 : 그래서 교사는이 코드 조각을 사용하여 그는
교사 코드를 썼다.
지금 여기 내 자신의 코드는 동일한 작업을 수행하려고 노력하고 있습니다.
public IEnumerable<Todo> GetTodos(string q= null,string sort = null, bool desc = false, int ? limit = null, int offset =0)
{
var result = Models.DbStoredProcModel.GetAllTodos.GetAllTodoEntryStoredProcedure();
IQueryable<Todo> items = string.IsNullOrEmpty(sort)
? result.OrderBy(o => o.Priority)
// i get the error on the line below
: result.OrderBy(String.Format("it. {0} {1}", sort, desc ? "DESC" : "ASC"));
if (!string.IsNullOrEmpty(q) && q != "undefined")
items = items.Where(t => t.Text.Contains(q));
if (offset > 0) items = items.Skip(offset);
if (limit.HasValue) items = items.Take(limit.Value);
return items;
}
그러나, 나는 오류가
Error:The type arguments for method
'System.Linq.Enumerable.OrderBy<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
가 어떻게이 문제를 해결 않는다는 것을 말하는거야?
스토어드 프로 시저 (IQueryable을 반환하지 않음)를 사용 중이므로'items'에 할당하려고하면 실패 할 것이라고 생각합니다. 실제로 매개 변수를 저장 프로 시저에 전달해야합니다. – markpsmith
문자열을 받아들이는 OrderBy extesion 버전이 있습니까? http://msdn.microsoft.com/pt-br/library/system.linq.queryable.orderby(v=vs.110).aspx – gustavodidomenico
여기에서와 같이, 나는 "OrderBy"메소드를 인식하지 못한다. 문자열을 매개 변수로 사용합니다. 더 많은 정보를 제공해야합니다. 내가 말했듯이 –