Breeze Projection Query,无法找到属性

时间:2013-10-28 17:27:51

标签: entity-framework breeze

我收到错误无法在类型'System.Web.Http.OData.Query.Expressions.SelectExpandBinder + SelectSome`1 [CSCode.Sessions_Sessions]'上找到属性'SessionID'。

我首先使用Entity Framework数据库,使用所有默认设置从现有数据库生成模型。

在我将.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;
}

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

1 个答案:

答案 0 :(得分:0)

2013年10月28日更新:

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

以下老帖子:

此错误是由于Microsoft对WebApi(新版本称为WebApi 2)和实体框架(EF5 - &gt; EF6)的更改。

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

目前,它有点痛苦,但您需要手动安装旧版(v 4.x)版本的“Microsoft.AspNet.WebApi.xxx”软件包和旧版Entity Framework v5(不是v6)在VS 2013上安装Breeze。

[1]: