我收到错误Unable to locate property 'SessionID' on type 'System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[CSCode.Sessions_Sessions]'。
我首先使用实体框架数据库,从具有所有默认设置的现有数据库生成模型。
在我将 .select 投影添加到查询之前,一切都很好。
$(function () {
my.manager = new breeze.EntityManager("api/breeze");
my.vm = function () {
var sessions = ko.observableArray([]);
var load = function () {
var p1 = new breeze.Predicate("FormatID", "!=", "11");
var p2 = new breeze.Predicate("Year", "==", "2014");
var p3 = new breeze.Predicate("Approved", "==", "true");
var p4 = new breeze.Predicate("StartTime", "!=", null);
var predicates = breeze.Predicate.and([p1, p2, p3]);
var query = breeze.EntityQuery.from("Sessions_Sessions")
.where(predicates)
.select("SessionID, Title, Topic, PDTrackID, RoomID");
return my.manager.executeQuery(query).then(querySucceeded).fail(queryFailed);
function querySucceeded(data) {
my.vm.sessions(data.results);
}f;
function queryFailed(error) {
$("#error").text(error.message);
};
};
return {
sessions: sessions,
load: load
};
}();
my.vm.load();
ko.applyBindings(my.vm);
它正在使用此地址查询 api:
api/breeze/Sessions_Sessions?$filter=(FormatID%20ne%2011)%20and%20(Year%20eq%202014)%20and%20(Approved%20eq%20true)&$select=SessionID%2CTitle%2CTopic%2CPDTrackID%2CRoomID
返回此错误消息:
{
$id: "1",
$type: "System.Web.Http.HttpError, System.Web.Http",
Message: "An error has occurred.",
ExceptionMessage: "Unable to locate property 'SessionID' on type 'System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[CSCode.Sessions_Sessions]'.",
ExceptionType: "System.Exception",
StackTrace: " at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()"
}
这是控制器类:
readonly EFContextProvider<FMEAMobileEntities> _contextProvider = new EFContextProvider<FMEAMobileEntities>();
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[HttpGet]
public IQueryable<Sessions_Sessions> Sessions_Sessions()
{
return _contextProvider.Context.Sessions_Sessions;
}
我假设我错过了配置实体框架或控制器类的步骤,但我在文档中找不到任何内容。任何指导将不胜感激。