0

我收到错误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;
}

我假设我错过了配置实体框架或控制器类的步骤,但我在文档中找不到任何内容。任何指导将不胜感激。

4

1 回答 1

0

2013 年 10 月 28 日更新:

截至目前,Breeze 1.4.5 已支持 Microsoft 的 ASP.NET WebApi 2 和 Entity Framework 6。请参阅http://www.breezejs.com/documentation/download

旧帖如下:

这个错误是因为微软对 WebApi(新版本称为 WebApi 2)和实体框架(EF5 -> EF6)的更改。

我们将在本周晚些时候发布 Breeze 对 WebApi2 和 Entity Framework 6 的支持。

现在,它有点痛苦,但在安装 Breeze 之前,您需要手动安装“Microsoft.AspNet.WebApi.xxx”包的旧(v 4.x)版本和旧实体框架 v5(不是 v6)与 2013 年相比。

[1]:

于 2013-10-28T19:14:50.937 回答