0
votes

I receive the following error when trying to run the new project per the instruction in the Readme file.

1: querying Todos

2: Query failed: The action 'Todos' on controller 'BreezeSample' with return type 'System.Collections.Generic.List`1[[MyTasks.Api.Models.BreezeSampleTodoItem, MyTasks.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot support querying. Ensure the type of the returned content is IEnumerable, IQueryable, or a generic form of either interface.

UPDATE:

I checked my event viewer, and see a SQL error that I've never seen before when trying to debug on my machine -

Login failed for user 'my-machine\user-name'. Reason: Failed to open the explicitly specified database. [CLIENT: ]

It seems that the database being generated by BreezeSamplesContext is inaccessible for some reason? It has been generated by code-first, but I can't query it (apparently).

UPDATE 2:

I've changed the default method to -

[HttpGet]
public IQueryable<BreezeSampleTodoItem> Todos()
{
    System.Data.Entity.DbSet<BreezeSampleTodoItem> result = null;
    try
    {
        result = _contextProvider.Context.Todos;
    }
    catch (Exception exc)
    {
        throw new Exception(exc.Message);
    }
    return result;
}

Although the Seed method works, and the database is dropped and repopulated with seed values, I get a response of 0 items in the 'result' above.

2

2 Answers

5
votes

UPDATE: December 15

The critical piece of information ... the reason for the problem ... is the use of the pre-release SPA template.

That template is not the same as the MVC 4 Web API or Empty templates that are described in the Breeze documentation

The SPA Template and the MVC update include the beginnings of ASP.NET Web API support for OData queries. Their stab at OData conflicts with Breeze; the two forces are wrestling for ownership of the OData query. Wish we could use theirs but it is missing essential features such as support for $select and $expand.

Fortunately, it is easy to disable the MS version so that Breeze prevails. Open App_Start/WebApiConfig.cs file and delete or comment out the following:

config.EnableQuerySupport(); // conflicts with Breeze's ODataActionFilter

The misleading error about "return type" should disappear and you should be back in business.

Note that taking this step turns off the MS Web API OData filter for the entire site. We have it on our backlog to update the Breeze ODataActionFilterAttribute so that it disables the MS Web API OData handling for the Breeze controller only. We hadn't bothered yet because the SPA template remains unofficial at this time. For the nonce ... you can't mix Breeze and Web API OData queries in the same site ... unless you're prepared to do the per-controller filter cleanup yourself.

We have a Breeze version of the new SPA Template working and almost ready to release. I'll be writing about it shortly and will update this answer with a link.

Below is my previous answer which I preserve mostly because (a) it describes how to diagnose a problem and (b) is the context for the comment chain.


Let's start over and see if we can diagnose. Close all Visual Studio sessions (that should stop IIS Express). Launch a fresh VS session. Create an MVC4 Web Api application in VS 2012. Add the Breeze.MVC4WebApiClientSample NuGet package. Run it (F5). Still having trouble?

If so, let's update the controller method with a new line like this:

[HttpGet]
public IQueryable Todos() {
    var items = _contextProvider.Context.Todos.ToList(); // test the query
    return _contextProvider.Context.Todos;
}

Put a breakpoint on the var items ... line and re-run with the debugger (F5). Step into that line. Did it throw (not good but interesting)? If not, how many items did you get? Zero? You should have 6.

If you can't get past this point, I don't think this is a Breeze problem. Breeze hasn't done anything yet. I'd be looking for something unexpected in your environment.

Let us know how it stands when you get to this point; if still stuck we'll be ready for next steps.

0
votes

The sample from NuGet is set up to drop and re-create the database every time you run the code. Do you happen to have the database open in a SQL Management Studio? I ran into this as well.

Take a look at the BreezeSampleDatabaseInitializer class. Check out the comment that talks about preserving the changes between server sessions. If you change the class to implement the DropCreateDatabaseIfModelChanges interface it will only try to drop the database when you change the model.