0
votes

I am using Breeze with much success in my SPA, but seem to be stuck when trying to return parent->child data in a single query by using expand().

When doing a single table query, the $type in the JSON return is correct:

$type: MySPA.Models.Challenge, MySPA without Expand

However if I use expand() in my query I get the relational data, but the $type is this:

System.Collections.Generic.Dictionary 2[[System.String, mscorlib],[System.Object, mscorlib]]

with Expand

Because of the $type is not the proper table + namespace, the client side code can't tell that this is an entity and exposes it as JSON and not a Breeze object (with observables, entityAspect, etc.).

At first I was using my own ContextProvider so that I could override the Before/After saving methods. When I had these problems, I reverted back to the stock EFContextProvider<>.

I am using EF5 in a database first mode.

Here's my controller code:

[BreezeController]
public class DataController : ApiController
{
    // readonly ModelProvider _contextProvider = new ModelProvider();
    readonly EFContextProvider<TestEntities> _contextProvider = new EFContextProvider<TestEntities>();

    [HttpGet]
    public string Metadata()
    {
        return _contextProvider.Metadata();
    }

    [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
    [HttpGet]
    public IQueryable<Challenge> Challenges()
    {
        return _contextProvider.Context.Challenges; 
    }

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return _contextProvider.SaveChanges(saveBundle);
    }       
    public IQueryable<ChallengeNote> ChallengeNotes()
    {       
        return _contextProvider.Context.ChallengeNotes;
    }
}

Here's my BreezeWebApiConfig.cs

 public static void RegisterBreezePreStart()
  {
      GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);

      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "BreezeApi",
          routeTemplate: "breeze/{controller}/{action}"
      );
  }

Is there a configuration setting that I am missing?

2
Please show both relevant types in your EF model and your client side query... and whether you have any breeze.NamingConvention set. Also take a look at the Breeze DocCode sample, there are several examples of "expand" shown there. - Jay Traband
At this point, I'm bypassing the Breeze client libraries - as you can see from the images above, this is about the response from the server. !image for my model - Carol AndorMarten Liebster

2 Answers

1
votes

Did you try "expanding" on server side? Is it needed to do expand on client side? I tried to do expand before but failed for me as well, did some research and decided I'd rather place it on server:

[HttpGet]
public IQueryable<Challenge> ChallengesWithNotes()
    {
        return _contextProvider.Context.Challenges.Include("ChallengeNotes"); 
    }

This should be parsed as expected. On client side you would query for "ChallengeNotes" instead of "Challenges" and you wouldn't need to write expand part.

0
votes

I strongly suspect that the problem is due to your use of the [Queryable] attribute.

You must use the [BreezeQueryable] attribute instead!

See the documentation on limiting queries.

We are aware that Web API's QueryableAttribute has been deprecated in favor of EnableQueryAttribute in Web API v.1.5. Please stick with BreezeQueryable until we've had a chance to write a corresponding derived attribute for EnableQuery. Check with the documentation for the status of this development.