0
votes

I'm getting the error Unable to locate property 'SessionID' on type 'System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[CSCode.Sessions_Sessions]'.

I'm using Entity Framework database first, generated model from an existing database with all the default settings.

Everything works great until I add the .select projection to the query.

$(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);

It's querying the api with this address:

api/breeze/Sessions_Sessions?$filter=(FormatID%20ne%2011)%20and%20(Year%20eq%202014)%20and%20(Approved%20eq%20true)&$select=SessionID%2CTitle%2CTopic%2CPDTrackID%2CRoomID

which returns this error message:

{
$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()"
}

This is the controller class:

 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;
}

I'm assuming that I missed a step in configuring Entity Framework or the controller class but I can't find anything in the docs. Any guidance would be greatly appreciated.

1

1 Answers

0
votes

Updated 10/28/2013:

As of now, Breeze 1.4.5 has support for Microsoft's ASP.NET WebApi 2 and Entity Framework 6. Please see http://www.breezejs.com/documentation/download.

Old Post below:

This bug is because of Microsoft's changes to WebApi ( the new version is called WebApi 2) and Entity Framework ( EF5 -> EF6).

We will be releasing Breeze support for both WebApi2 and Entity Framework 6 later this week.

For now, its a bit painful, but you need to manually install the older ( v 4.x) versions of the "Microsoft.AspNet.WebApi.xxx" packages and the older Entity Framework v5 (not v6), before installing Breeze on VS 2013.

[1]: